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:使用数据库连接池。

  • 相关阅读:
    jar强退出 JVM报错:Failed to write core dump. Core dumps have been disabled.
    配置 DHCP Snooping 和 IPSG
    OpenOffice
    RabbitMQ ADD
    YAPI 接口管理
    mysql:1153 Got a packet bigger than ‘max_allowed_packet’ bytes的解决方法
    修改端口的VLAN
    阿里云OSS设置跨域访问
    seata连接nacos 报错
    Linux登录超时问题
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/8046003.html
Copyright © 2011-2022 走看看