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:使用數據庫連接池。