Add one stage pipeline to /ok

This commit is contained in:
2025-08-22 14:28:17 -04:00
parent c536522f21
commit f43e623a7e
5 changed files with 52 additions and 12 deletions

View File

@@ -337,7 +337,7 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
// Process existing connections in batch
if (batch_count > 0) {
process_connection_batch(epollfd, {batch, (size_t)batch_count},
{batch_events, (size_t)batch_count}, false);
{batch_events, (size_t)batch_count});
}
// Only accept on listen sockets that epoll indicates are ready
@@ -372,6 +372,15 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
perror("setsockopt SO_KEEPALIVE");
}
// Add to epoll with no interests
struct epoll_event event{};
event.events = 0;
event.data.fd = fd;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event) == -1) {
perror("epoll_ctl ADD");
(void)connection_registry_.remove(fd);
}
// Transfer ownership from registry to batch processing
size_t epoll_index = thread_id % epoll_fds_.size();
batch[batch_count] = std::unique_ptr<Connection>(new Connection(
@@ -385,8 +394,7 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
// Process batch if full
if (batch_count == config_.server.event_batch_size) {
process_connection_batch(epollfd, {batch, (size_t)batch_count},
{batch_events, (size_t)batch_count},
true);
{batch_events, (size_t)batch_count});
batch_count = 0;
}
} // End inner accept loop
@@ -395,7 +403,7 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
// Process remaining accepted connections
if (batch_count > 0) {
process_connection_batch(epollfd, {batch, (size_t)batch_count},
{batch_events, (size_t)batch_count}, true);
{batch_events, (size_t)batch_count});
batch_count = 0;
}
}
@@ -460,7 +468,7 @@ 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, bool is_new) {
std::span<const int> events) {
// First process I/O for each connection
for (size_t i = 0; i < batch.size(); ++i) {
if (batch[i]) {
@@ -487,9 +495,8 @@ void Server::process_connection_batch(
// Put connection back in registry since handler didn't take ownership.
// Must happen before epoll_ctl
connection_registry_.store(fd, std::move(conn_ptr));
int epoll_op = is_new ? EPOLL_CTL_ADD : EPOLL_CTL_MOD;
if (epoll_ctl(epollfd, epoll_op, fd, &event) == -1) {
perror(is_new ? "epoll_ctl ADD" : "epoll_ctl MOD");
if (epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, &event) == -1) {
perror("epoll_ctl MOD");
(void)connection_registry_.remove(fd);
}
}