Limits and performance
Thread pools
The server has two thread pools, so that streams, health watchers and slow calls cannot take the threads that stops need:
- The general pool serves every RPC except
SendCommand. It has 32 threads by default;create_server(max_workers=n)changes that. - The command pool serves
SendCommandalone. It hasmax_workers // 2threads, at least 4.
Commands that are not stops may use every command pool thread but two, which are kept for stops.
In the general pool, two threads are kept for short calls. Health Watch calls get at most half
of the rest and never more than 4. Streams and WaitComplete calls share what remains. The
streams are StreamStatus, StreamErrors and the HAL service’s StreamStatus and
WatchValues.
| Workers | Health watchers | Streams and WaitComplete | Command pool | Commands that are not stops |
|---|---|---|---|---|
| 1 | 0 | 0 | 4 | 2 |
| 4 | 1 | 1 | 4 | 2 |
| 10 | 4 | 4 | 5 | 3 |
| 32 (default) | 4 | 26 | 16 | 14 |
What a client sees past each limit:
- One more stream or
WaitCompletefails withRESOURCE_EXHAUSTEDbefore it starts. With 2 workers or fewer every stream andWaitCompleteis refused. - One more command is answered
RCS_ERRORwithnot_senttrue and the messageToo many commands are waiting; the command was not sent. - One more health
Watchfails withUNIMPLEMENTED. Use healthCheckinstead. - Stops are never counted or refused.
The other RPCs are not counted: GetStatus, GetMachineConfig, ResolveFile, GetServerInfo,
the file RPCs, the HAL queries and health Check. They cannot take command pool threads.
A stream holds its thread for as long as it lasts, and a WaitComplete holds one while it waits.
A stream gives its thread back as soon as the client cancels or disconnects, whatever its
interval. A command waiting for its turn whose client has gone gives its thread back within about
0.1 seconds, unless it is a stop.
The pools cannot protect stops from a flood of commands. The server sees a
SendCommandcall before it reads the request, so it cannot tell a stop from any other command, and it runs calls in the order they arrive. A client that sendsSendCommandcalls faster than they are refused queues them ahead of every stop. The server has no authentication, so never expose the port (see Security considerations).
Stream intervals
StreamStatus sends a status every 100 ms by default. A client sets interval_ms in the
request:
request = linuxcnc_pb2.StreamStatusRequest(interval_ms=50)An interval_ms of 0 or less means 100 ms. The longest interval is 60 seconds: a larger value is
treated as 60000. The same rules apply to the HAL service’s StreamStatus and WatchValues.
Use a stream rather than polling GetStatus for live data.
Connection limits
- Keepalive: the server sends a keepalive ping every 30 seconds and closes a connection whose ping is not answered within 10 seconds.
- Message size: the server accepts requests of up to 11 MiB, the 10 MiB
UploadFilelimit plus room for the rest of the request. A larger request fails withRESOURCE_EXHAUSTED.