diff --git a/config.example.json b/config.example.json index 285a2724..4e6f49cd 100644 --- a/config.example.json +++ b/config.example.json @@ -47,7 +47,8 @@ //is_fast: false by default, if it is true, the client is faster but user can't call //any synchronous interface of it. "is_fast": false, - //connection_number: 1 by default, valid only if is_fast is false. + //connection_number: 1 by default, if the 'is_fast' is true, the number is the number of + connections per IO thread, otherwise it is the total number of all connections. "connection_number": 1 } ],*/ diff --git a/drogon_ctl/templates/config.csp b/drogon_ctl/templates/config.csp index ffaf4419..ef4bbaf9 100644 --- a/drogon_ctl/templates/config.csp +++ b/drogon_ctl/templates/config.csp @@ -47,7 +47,8 @@ //is_fast: false by default, if it is true, the client is faster but user can't call //any synchronous interface of it. "is_fast": false, - //connection_number: 1 by default, valid only if is_fast is false. + //connection_number: 1 by default, if the 'is_fast' is true, the number is the number of + connections per IO thread, otherwise it is the total number of all connections. "connection_number": 1 } ],*/ diff --git a/lib/src/HttpAppFrameworkImpl.cc b/lib/src/HttpAppFrameworkImpl.cc index c055e12d..e4ba88d6 100644 --- a/lib/src/HttpAppFrameworkImpl.cc +++ b/lib/src/HttpAppFrameworkImpl.cc @@ -521,7 +521,10 @@ void HttpAppFrameworkImpl::createDbClients( _dbFastClientsMap[dbInfo._name][loop] = std::shared_ptr( new drogon::orm::DbClientLockFree( - dbInfo._connectionInfo, loop, dbInfo._dbType)); + dbInfo._connectionInfo, + loop, + dbInfo._dbType, + dbInfo._connectionNumber)); } } } diff --git a/orm_lib/src/DbClientLockFree.cc b/orm_lib/src/DbClientLockFree.cc index 31a467f9..d4f7a9d3 100644 --- a/orm_lib/src/DbClientLockFree.cc +++ b/orm_lib/src/DbClientLockFree.cc @@ -41,8 +41,9 @@ using namespace drogon::orm; DbClientLockFree::DbClientLockFree(const std::string &connInfo, trantor::EventLoop *loop, - ClientType type) - : _connInfo(connInfo), _loop(loop) + ClientType type, + size_t connectionNumberPerLoop) + : _connInfo(connInfo), _loop(loop), _connectionNum(connectionNumberPerLoop) { _type = type; LOG_TRACE << "type=" << (int)type; diff --git a/orm_lib/src/DbClientLockFree.h b/orm_lib/src/DbClientLockFree.h index 45121b75..1eecc0d9 100644 --- a/orm_lib/src/DbClientLockFree.h +++ b/orm_lib/src/DbClientLockFree.h @@ -35,7 +35,8 @@ class DbClientLockFree : public DbClient, public: DbClientLockFree(const std::string &connInfo, trantor::EventLoop *loop, - ClientType type); + ClientType type, + size_t connectionNumberPerLoop); virtual ~DbClientLockFree() noexcept; virtual void execSql(std::string &&sql, size_t paraNum, @@ -55,7 +56,7 @@ class DbClientLockFree : public DbClient, std::string _connInfo; trantor::EventLoop *_loop; DbConnectionPtr newConnection(); - const size_t _connectionNum = 4; + const size_t _connectionNum; std::vector _connections; std::vector _connectionHolders; std::unordered_set _transSet;