Tsqldbserverhttpapi using the worker thread pool
When Tsqldbserverhttpapi is created, the default is to use single-threaded mode, and only one database connection is used, and the server should handle a large number of clients relying on only one worker thread (the main thread) and one database connection.
The main thread of the server is not too busy to die! Yes, clients don't wait to die!
Take code as proof:
Tsqldbserverhttpapi = Class (Tsqldbserverabstract)
Protected
Public
Publish the SYNDB connection on a given HTTP port and URI using. sys
-URI would follow the supplied adatabasename parameter on the given port
e.g. Http://serverip:8092/remotedb for
// ! Create (aprops, ' remotedb ');
-You can optionally register one user credential
Constructor Create (aproperties:tsqldbconnectionproperties;
Const ADATABASENAME:RAWUTF8; Const Aport:rawutf8=syndb_default_http_port;
Const ausername:rawutf8= '; Const apassword:rawutf8= ';
Ahttps:boolean=false;
Athreadpoolcount:integer=1; Use a total of one worker thread (the main thread, of course)
Aprotocol:tsqldbproxyconnectionprotocolclass=nil;
Athreadmode:tsqldbconnectionpropertiesthreadsafethreadingmode=tmmainconnection//using a database connection
); Override
End
Now the CPU is multi-core, for the hair does not open multi-work threads to deal with a large number of clients?
This, Mormot's author also thought for us. It's so happy!
As long as we specify the parameters when Tsqldbserverhttpapi is created:
Tsqldbserverhttpapi.create (DataBase, ' JJ ', ' 6789 ', ' admin ', ' admin ', False, 8, nil, tmthreadpool);
8: The thread pool creates 8 worker threads, which depends on the number of CPU cores.
Tmthreadpool: Use a database connection pool.
Tsqldbserverhttpapi using the worker thread pool