Remove vestigial "round-robin" code

This commit is contained in:
2025-09-15 11:22:14 -04:00
parent 1cb7a4c301
commit afd240dba7
2 changed files with 9 additions and 15 deletions

View File

@@ -164,7 +164,7 @@ int Server::create_local_connection() {
struct sockaddr_storage addr{}; struct sockaddr_storage addr{};
addr.ss_family = AF_UNIX; 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 = size_t epoll_index =
connection_distribution_counter_.fetch_add(1, std::memory_order_relaxed) % connection_distribution_counter_.fetch_add(1, std::memory_order_relaxed) %
epoll_fds_.size(); epoll_fds_.size();
@@ -219,7 +219,8 @@ void Server::setup_shutdown_pipe() {
} }
void Server::create_epoll_instances() { 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); epoll_fds_.resize(config_.server.io_threads);
for (int i = 0; i < config_.server.io_threads; ++i) { 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<std::thread> &threads) { void Server::start_io_threads(std::vector<std::thread> &threads) {
int io_threads = config_.server.io_threads; int io_threads = config_.server.io_threads;
@@ -268,8 +264,8 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
pthread_setname_np(pthread_self(), pthread_setname_np(pthread_self(),
("io-" + std::to_string(thread_id)).c_str()); ("io-" + std::to_string(thread_id)).c_str());
// Each thread uses its assigned epoll instance (round-robin) // Each thread uses its assigned epoll instance (1:1 mapping)
int epollfd = get_epoll_for_thread(thread_id); int epollfd = epoll_fds_[thread_id];
std::vector<epoll_event> events(config_.server.event_batch_size); std::vector<epoll_event> events(config_.server.event_batch_size);
std::vector<Ref<Connection>> batch(config_.server.event_batch_size); std::vector<Ref<Connection>> batch(config_.server.event_batch_size);
@@ -374,7 +370,7 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
} }
// Transfer ownership from registry to batch processing // 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<Connection>( batch[batch_count] = make_ref<Connection>(
addr, fd, addr, fd,
connection_id_.fetch_add(1, std::memory_order_relaxed), connection_id_.fetch_add(1, std::memory_order_relaxed),

View File

@@ -124,13 +124,14 @@ private:
std::atomic<int64_t> connection_id_{0}; std::atomic<int64_t> connection_id_{0};
std::atomic<int> active_connections_{0}; std::atomic<int> active_connections_{0};
// Round-robin counter for connection distribution // Round-robin counter for local connection distribution across epoll
// instances
std::atomic<size_t> connection_distribution_counter_{0}; std::atomic<size_t> connection_distribution_counter_{0};
// Shutdown coordination // Shutdown coordination
int shutdown_pipe_[2] = {-1, -1}; 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<int> epoll_fds_; std::vector<int> epoll_fds_;
std::vector<int> std::vector<int>
listen_fds_; // FDs to accept connections on (Server owns these) listen_fds_; // FDs to accept connections on (Server owns these)
@@ -141,9 +142,6 @@ private:
void create_epoll_instances(); void create_epoll_instances();
void start_io_threads(std::vector<std::thread> &threads); void start_io_threads(std::vector<std::thread> &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 // Helper for processing connection I/O
void process_connection_reads(Ref<Connection> &conn, int events); void process_connection_reads(Ref<Connection> &conn, int events);
void process_connection_writes(Ref<Connection> &conn, int events); void process_connection_writes(Ref<Connection> &conn, int events);