Add an index to thread pipeline iterators for load balancing
This commit is contained in:
@@ -51,6 +51,22 @@ void HttpHandler::on_write_progress(std::unique_ptr<Connection> &conn_ptr) {
|
||||
}
|
||||
}
|
||||
|
||||
void HttpHandler::on_post_batch(std::span<std::unique_ptr<Connection>> batch) {
|
||||
int readyCount = 0;
|
||||
for (int i = 0; i < int(batch.size()); ++i) {
|
||||
readyCount += batch[i] && batch[i]->outgoingBytesQueued() > 0;
|
||||
}
|
||||
if (readyCount > 0) {
|
||||
auto guard = pipeline.push(readyCount, /*block=*/true);
|
||||
auto outIter = guard.batch.begin();
|
||||
for (int i = 0; i < int(batch.size()); ++i) {
|
||||
if (batch[i] && batch[i]->outgoingBytesQueued() > 0) {
|
||||
*outIter++ = std::move(batch[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HttpHandler::on_data_arrived(std::string_view data,
|
||||
std::unique_ptr<Connection> &conn_ptr) {
|
||||
auto *state = static_cast<HttpConnectionState *>(conn_ptr->user_data);
|
||||
@@ -112,13 +128,6 @@ void HttpHandler::on_data_arrived(std::string_view data,
|
||||
handleNotFound(*conn_ptr, *state);
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
auto guard = ok_pipeline.push(1, true);
|
||||
for (auto &c : guard.batch) {
|
||||
c = std::move(conn_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user