Allow multiple epoll instances on server

This commit is contained in:
2025-08-21 14:13:11 -04:00
parent 22e638e1f9
commit 1cce8d9950
5 changed files with 98 additions and 40 deletions

View File

@@ -103,11 +103,14 @@ private:
std::vector<std::thread> threads_;
std::atomic<int64_t> connection_id_{0};
// Round-robin counter for connection distribution
std::atomic<size_t> connection_distribution_counter_{0};
// Shutdown coordination
int shutdown_pipe_[2] = {-1, -1};
// Epoll file descriptor
int epollfd_ = -1;
// Multiple epoll file descriptors to reduce contention
std::vector<int> epoll_fds_;
int listen_sockfd_ = -1;
// Unique tags for special events to avoid type confusion in epoll data union
@@ -118,14 +121,19 @@ private:
void setup_shutdown_pipe();
void setup_signal_handling();
int create_listen_socket();
void create_epoll_instances();
void start_io_threads();
void cleanup_resources();
// 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_io(std::unique_ptr<Connection> &conn, int events);
// Helper for processing a batch of connections with their events
void process_connection_batch(std::span<std::unique_ptr<Connection>> batch,
void process_connection_batch(int epollfd,
std::span<std::unique_ptr<Connection>> batch,
std::span<const int> events, bool is_new);
/**