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

  • 相关阅读:
    AutoFac (控制反转IOC 与依赖注入DI)
    【干货】利用MVC5+EF6搭建博客系统(一)EF Code frist、实现泛型数据仓储以及业务逻辑
    Log4.Net 在Winfrom、MVC、ashx程序里的使用,ashx程序里使用异步
    触发器
    游标的使用
    sql数据库快照与恢复 规则绑定
    磁盘恢复
    修改sql数据库名称
    MVC学习笔记
    NuGet包和功能
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/8046003.html
Copyright © 2011-2022 走看看