Make all listeners share IO threads in the MacOS system

This commit is contained in:
antao 2019-07-09 17:23:06 +08:00
parent ec276b4948
commit 7d7537b562
4 changed files with 30 additions and 10 deletions

View File

@ -390,12 +390,14 @@ void HttpAppFrameworkImpl::run()
}
}
#else
auto loopThreadPtr =
std::make_shared<EventLoopThread>("DrogonListeningLoop");
loopThreads.push_back(loopThreadPtr);
auto ioLoopThreadPoolPtr =
std::make_shared<EventLoopThreadPool>(_threadNum);
for (auto const &listener : _listeners)
{
LOG_TRACE << "thread num=" << _threadNum;
auto loopThreadPtr =
std::make_shared<EventLoopThread>("DrogonListeningLoop");
loopThreads.push_back(loopThreadPtr);
auto ip = std::get<0>(listener);
bool isIpv6 = ip.find(":") == std::string::npos ? false : true;
auto serverPtr = std::make_shared<HttpServer>(
@ -420,7 +422,7 @@ void HttpAppFrameworkImpl::run()
serverPtr->enableSSL(cert, key);
#endif
}
serverPtr->setIoLoopNum(_threadNum);
serverPtr->setIoLoopThreadPool(ioLoopThreadPoolPtr);
serverPtr->setHttpAsyncCallback(
std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2));
serverPtr->setNewWebsocketCallback(std::bind(
@ -429,13 +431,13 @@ void HttpAppFrameworkImpl::run()
std::bind(&HttpAppFrameworkImpl::onConnection, this, _1));
serverPtr->kickoffIdleConnections(_idleConnectionTimeout);
serverPtr->start();
auto serverIoLoops = serverPtr->getIoLoops();
for (auto serverIoLoop : serverIoLoops)
{
ioLoops.push_back(serverIoLoop);
}
servers.push_back(serverPtr);
}
auto serverIoLoops = ioLoopThreadPoolPtr->getLoops();
for (auto serverIoLoop : serverIoLoops)
{
ioLoops.push_back(serverIoLoop);
}
#endif
#if USE_ORM

View File

@ -64,6 +64,11 @@ class HttpServer : trantor::NonCopyable
{
_connectionCallback = cb;
}
void setIoLoopThreadPool(
const std::shared_ptr<trantor::EventLoopThreadPool> &pool)
{
_server.setIoLoopThreadPool(pool);
}
void setIoLoopNum(int numThreads)
{
_server.setIoLoopNum(numThreads);

View File

@ -100,6 +100,13 @@ MysqlConnection::MysqlConnection(trantor::EventLoop *loop,
0);
// LOG_DEBUG << ret;
auto fd = mysql_get_socket(_mysqlPtr.get());
if (fd < 0)
{
LOG_FATAL << "Socket fd < 0, Usually this is because the number of "
"files opened by the program exceeds the system "
"limit. Please use the ulimit command to check.";
exit(-1);
}
_channelPtr =
std::unique_ptr<trantor::Channel>(new trantor::Channel(loop, fd));
_channelPtr->setCloseCallback([=]() {

View File

@ -45,7 +45,13 @@ PgConnection::PgConnection(trantor::EventLoop *loop,
_channel(loop, PQsocket(_connPtr.get()))
{
PQsetnonblocking(_connPtr.get(), 1);
// assert(PQisnonblocking(_connPtr.get()));
if (_channel.fd() < 0)
{
LOG_FATAL << "Socket fd < 0, Usually this is because the number of "
"files opened by the program exceeds the system "
"limit. Please use the ulimit command to check.";
exit(-1);
}
_channel.setReadCallback([=]() {
if (_status != ConnectStatus_Ok)
{