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 SendCommand alone. It has max_workers // 2 threads, 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.

WorkersHealth watchersStreams and WaitCompleteCommand poolCommands that are not stops
10042
41142
104453
32 (default)4261614

What a client sees past each limit:

  • One more stream or WaitComplete fails with RESOURCE_EXHAUSTED before it starts. With 2 workers or fewer every stream and WaitComplete is refused.
  • One more command is answered RCS_ERROR with not_sent true and the message Too many commands are waiting; the command was not sent.
  • One more health Watch fails with UNIMPLEMENTED. Use health Check instead.
  • 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 SendCommand call 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 sends SendCommand calls 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 UploadFile limit plus room for the rest of the request. A larger request fails with RESOURCE_EXHAUSTED.