#1 2024-10-28 15:32:57

zen010101
Member
Registered: 2024-06-15
Posts: 66

Why limit the max number of ServerThreadPoolCount to 4?

While I was researching the mORMot source, I found the following code:

constructor TWebSocketServer.Create(const aPort: RawUtf8;
  const OnStart, OnStop: TOnNotifyThread; const ProcessName: RawUtf8;
  ServerThreadPoolCount, KeepAliveTimeOut: integer;
  ProcessOptions: THttpServerOptions);
begin
  ....
  if ServerThreadPoolCount > 4 then
    ServerThreadPoolCount := 4; // don't loose threads for nothing
  // start the server
  inherited Create(aPort, OnStart, OnStop, ProcessName, ServerThreadPoolCount, ....
  ....
end;

Why do we need to limit ServerThreadPoolCount? Although I found the following explanation in the comments of Create, to be honest, I still don’t quite understand it:

....
    // - in the current implementation, the ServerThreadPoolCount parameter will
    // use two threads by default to handle shortliving HTTP/1.0 "connection: close"
    // requests, and one thread will be maintained per keep-alive/websockets client
    ....
    constructor Create(const aPort: RawUtf8;
      const OnStart, OnStop: TOnNotifyThread; const ProcessName: RawUtf8;
      ServerThreadPoolCount: integer = 2; KeepAliveTimeOut: integer = 30000;
      ProcessOptions: THttpServerOptions = []); override;

Offline

#2 2024-10-28 17:04:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,657
Website

Re: Why limit the max number of ServerThreadPoolCount to 4?

Because websockets with this TWebSocketServer class use the non-async server, so each websocket client connection uses its own thread on the server.
The thread pool is only used for HTTP/1.0 requests, which should not be used very much.
This is what the documentation says.

Offline

Board footer

Powered by FluxBB