zoukankan      html  css  js  c++  java
  • 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:使用数据库连接池。

  • 相关阅读:
    Array方面Js底层代码学习记录
    DOM 节点
    跨域
    狂雨cms代码审计:后台文件包含getshell
    在PHP一句话木马使用过程中的种种坑点分析
    记对某CMS的一次代码审计
    通达OA任意文件上传并利用文件包含导致远程代码执行漏洞分析
    DedeCMS V5.7 SP2后台存在代码执行漏洞
    zzzcms(php) v1.7.5 前台SQL注入及其他
    权限维持及后门持久化技巧总结
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/8046003.html
Copyright © 2011-2022 走看看