我已按照CppRestSdk
示例创建了客户端服务器系统服务器。
这是我的实现的示例代码部分(仅请求发送部分)。
nf.request(methods::POST, U("/"), requestBody)
.then([=] (pplx::task<http_response> task)
{
LOG_ENTRY;
// some other work ..
resp = task.get(); // fails
http_response resp;
do {
try {
resp = task.get();
} catch (std::exception& e) {
higLog("EXCEPTION CAUGHT: %s", e.what());
}
// some other checks ..
}while(0);
// process resp later ..
}
其中nf
是http_client
。
这是我的系统的体系结构。
主线程在epoll
服务器中运行front-end
循环。它还创建一个显式thread-pool
。 epoll
循环从客户端接收传入的消息,并将这些消息存储在work_queue中(由我实现)。线程池中的一个线程(池大小为500
)被唤醒,并从工作队列中选择一个job
。该线程对该消息执行处理,并使用cpprestsdk back-end
对象与http_client
服务器进行对话。
对于客户端中少量的并发线程(10
或15
),系统可以正常工作。但是,当我在客户端增加线程数(例如50
个线程)时,front-end
服务器开始显示不可预测的错误。通常,它会在task.get()函数中长时间阻塞。有时在捕获块中也显示“无法读取HTTP状态行”。
我是cpprestsdk
的新手。我不确定到底发生了什么。但据我猜测,backlog queue size
在back-end
服务器中很小。我找到了set_backlog()
函数,但是由于const引用而无法使用它。
line 307。
上述错误的原因可能是什么?这是常见的行为吗?是因为40
内部有cpprestsdk thread pool
个线程吗?