TSQLDBServerHttpApi使用工作线程池

TSQLDBServerHttpApi使用工作线程池

TSQLDBServerHttpApi创建时,默认是使用单线程模式,且只使用一个数据库连接,服务端要应对众多的客户端只靠一个工作线程(主线程)和一个数据库连接,

服务端主线程不忙死才怪!是的,客户端不等死才怪!

以代码为证:

TSQLDBServerHttpApi = class(TSQLDBServerAbstract)
protected
public
/// publish the SynDB connection on a given HTTP port and URI using http.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;  // 总共使用一个工作线程(当然是主线程)
aProtocol: TSQLDBProxyConnectionProtocolClass=nil;
aThreadMode: TSQLDBConnectionPropertiesThreadSafeThreadingMode=tmMainConnection // 使用一个数据库连接

); override;
end;

现在的CPU都是多核的,为毛不开启多工作线程来应对众多的客户端呢?

这点,MORMOT的作者也替我们想到了。太幸福了!

原来在TSQLDBServerHttpApi创建时只要我们指定参数即可:

TSQLDBServerHttpApi.Create(DataBase, 'jj', '6789', 'admin', 'admin', False, 8, nil, tmThreadPool); 

8:线程池创建8个工作线程,这个具体要根据自己的CPU核心数来定。

tmThreadPool:使用数据库连接池。

原文地址:https://www.cnblogs.com/hnxxcxg/p/8046003.html