Make the number of the connections of Fast DB Clients configurable

This commit is contained in:
antao 2019-07-08 18:21:18 +08:00
parent 64f9fc9acc
commit bcac1d4899
5 changed files with 14 additions and 7 deletions

View File

@ -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
}
],*/

View File

@ -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
}
],*/

View File

@ -521,7 +521,10 @@ void HttpAppFrameworkImpl::createDbClients(
_dbFastClientsMap[dbInfo._name][loop] =
std::shared_ptr<drogon::orm::DbClient>(
new drogon::orm::DbClientLockFree(
dbInfo._connectionInfo, loop, dbInfo._dbType));
dbInfo._connectionInfo,
loop,
dbInfo._dbType,
dbInfo._connectionNumber));
}
}
}

View File

@ -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;

View File

@ -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<DbConnectionPtr> _connections;
std::vector<DbConnectionPtr> _connectionHolders;
std::unordered_set<DbConnectionPtr> _transSet;