From afd240dba76ecb8626f4d913ee981bfd7d9c3870 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Mon, 15 Sep 2025 11:22:14 -0400 Subject: [PATCH] Remove vestigial "round-robin" code --- src/server.cpp | 16 ++++++---------- src/server.hpp | 8 +++----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index f3c1f36..ae68e5c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -164,7 +164,7 @@ int Server::create_local_connection() { struct sockaddr_storage addr{}; addr.ss_family = AF_UNIX; - // Calculate epoll_index for connection distribution + // Use round-robin distribution for local connections across epoll instances size_t epoll_index = connection_distribution_counter_.fetch_add(1, std::memory_order_relaxed) % epoll_fds_.size(); @@ -219,7 +219,8 @@ void Server::setup_shutdown_pipe() { } void Server::create_epoll_instances() { - // Create multiple epoll instances to reduce contention + // Create one epoll instance per I/O thread (1:1 mapping) to eliminate + // contention epoll_fds_.resize(config_.server.io_threads); for (int i = 0; i < config_.server.io_threads; ++i) { @@ -255,11 +256,6 @@ void Server::create_epoll_instances() { } } -int Server::get_epoll_for_thread(int thread_id) const { - // Round-robin assignment of threads to epoll instances - return epoll_fds_[thread_id % epoll_fds_.size()]; -} - void Server::start_io_threads(std::vector &threads) { int io_threads = config_.server.io_threads; @@ -268,8 +264,8 @@ void Server::start_io_threads(std::vector &threads) { pthread_setname_np(pthread_self(), ("io-" + std::to_string(thread_id)).c_str()); - // Each thread uses its assigned epoll instance (round-robin) - int epollfd = get_epoll_for_thread(thread_id); + // Each thread uses its assigned epoll instance (1:1 mapping) + int epollfd = epoll_fds_[thread_id]; std::vector events(config_.server.event_batch_size); std::vector> batch(config_.server.event_batch_size); @@ -374,7 +370,7 @@ void Server::start_io_threads(std::vector &threads) { } // Transfer ownership from registry to batch processing - size_t epoll_index = thread_id % epoll_fds_.size(); + size_t epoll_index = thread_id; batch[batch_count] = make_ref( addr, fd, connection_id_.fetch_add(1, std::memory_order_relaxed), diff --git a/src/server.hpp b/src/server.hpp index 7722507..81b88b5 100644 --- a/src/server.hpp +++ b/src/server.hpp @@ -124,13 +124,14 @@ private: std::atomic connection_id_{0}; std::atomic active_connections_{0}; - // Round-robin counter for connection distribution + // Round-robin counter for local connection distribution across epoll + // instances std::atomic connection_distribution_counter_{0}; // Shutdown coordination int shutdown_pipe_[2] = {-1, -1}; - // Multiple epoll file descriptors to reduce contention + // Multiple epoll file descriptors (1:1 with I/O threads) to reduce contention std::vector epoll_fds_; std::vector listen_fds_; // FDs to accept connections on (Server owns these) @@ -141,9 +142,6 @@ private: void create_epoll_instances(); void start_io_threads(std::vector &threads); - // Helper to get epoll fd for a thread using round-robin - int get_epoll_for_thread(int thread_id) const; - // Helper for processing connection I/O void process_connection_reads(Ref &conn, int events); void process_connection_writes(Ref &conn, int events);