Add an index to thread pipeline iterators for load balancing
This commit is contained in:
@@ -411,8 +411,8 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
|
||||
}
|
||||
}
|
||||
|
||||
void Server::process_connection_io(std::unique_ptr<Connection> &conn,
|
||||
int events) {
|
||||
void Server::process_connection_reads(std::unique_ptr<Connection> &conn,
|
||||
int events) {
|
||||
assert(conn);
|
||||
// Handle EPOLLIN - read data and process it
|
||||
if (events & EPOLLIN) {
|
||||
@@ -440,7 +440,11 @@ void Server::process_connection_io(std::unique_ptr<Connection> &conn,
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Server::process_connection_writes(std::unique_ptr<Connection> &conn,
|
||||
int events) {
|
||||
assert(conn);
|
||||
// Send immediately if we have outgoing messages (either from EPOLLOUT or
|
||||
// after reading)
|
||||
if ((events & EPOLLOUT) || ((events & EPOLLIN) && conn->hasMessages())) {
|
||||
@@ -469,10 +473,18 @@ void Server::process_connection_io(std::unique_ptr<Connection> &conn,
|
||||
void Server::process_connection_batch(
|
||||
int epollfd, std::span<std::unique_ptr<Connection>> batch,
|
||||
std::span<const int> events) {
|
||||
// First process I/O for each connection
|
||||
|
||||
// First process writes for each connection
|
||||
for (size_t i = 0; i < batch.size(); ++i) {
|
||||
if (batch[i]) {
|
||||
process_connection_io(batch[i], events[i]);
|
||||
process_connection_writes(batch[i], events[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Then process reads for each connection
|
||||
for (size_t i = 0; i < batch.size(); ++i) {
|
||||
if (batch[i]) {
|
||||
process_connection_reads(batch[i], events[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user