Skip to content
io-multiplexing logo

I/O Multiplexing for Game Servers

io-multiplexing

High-performance I/O multiplexing including epoll, IOCP, kqueue, and io_uring

SKILL.md

Full skill instructions

I/​O Multiplexing for Game Servers

Implement high-performance I/​O handling for thousands of concurrent connections.

I/​O Model Comparison

ModelPlatformConnectionsLatency
epollLinux100K+Low
kqueueBSD/​macOS100K+Low
IOCPWindows100K+Low
io_uringLinux 5.1+1M+Lowest
selectAll~1000Medium

Linux epoll

#include <sys/​epoll.h>

int epollfd = epoll_create1(0);

// Add socket
struct epoll_event ev;
ev.events = EPOLLIN | EPOLLET;  // Edge-triggered
ev.data.fd = client_socket;
epoll_ctl(epollfd, EPOLL_CTL_ADD, client_socket, &ev);

// Event loop
struct epoll_event events[MAX_EVENTS];
while (running) {
    int nfds = epoll_wait(epollfd, events, MAX_EVENTS, timeout_ms);
    for (int i = 0; i < nfds; i++) {
        if (events[i].events & EPOLLIN) handleRead(events[i].data.fd);
        if (events[i].events & EPOLLOUT) handleWrite(events[i].data.fd);
    }
}

Linux io_uring

#include <liburing.h>

struct io_uring ring;
io_uring_queue_init(256, &ring, 0);

// Submit read
struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
io_uring_prep_recv(sqe, socket_fd, buffer, BUFFER_SIZE, 0);
io_uring_sqe_set_data(sqe, &connection);
io_uring_submit(&ring);

// Reap completions
struct io_uring_cqe *cqe;
io_uring_wait_cqe(&ring, &cqe);
Connection* conn = io_uring_cqe_get_data(cqe);
handleCompletion(conn, cqe->res);
io_uring_cqe_seen(&ring, cqe);

Game Server Pattern

class GameServer {
    int epollfd;

    void run() {
        while (running) {
            pollEvents(16);  // 16ms = 60 FPS budget
            gameTick();
            broadcastState();
        }
    }

    void pollEvents(int timeout_ms) {
        struct epoll_event events[1024];
        int n = epoll_wait(epollfd, events, 1024, timeout_ms);
        for (int i = 0; i < n; i++) {
            handleEvent(events[i]);
        }
    }
};

Troubleshooting

Common Failure Modes

ErrorRoot CauseSolution
EMFILEToo many fdsIncrease ulimit
Missed eventsLevel-triggered bugUse edge-triggered
StarvationUnbalanced loadRound-robin
High latencyBlocking callAsync everything

Debug Checklist

# Check fd limits
ulimit -n

# Monitor fd usage
ls /​proc/​$(pgrep game-server)/​fd | wc -l

# Check epoll stats
cat /​proc/​$(pgrep game-server)/​fdinfo/​3

Unit Test Template

TEST(EpollServer, HandlesMultipleConnections) {
    EpollServer server(8080);
    vector<TcpClient> clients(100);

    for (auto& client : clients) {
        client.connect("localhost", 8080);
    }

    EXPECT_EQ(server.connectionCount(), 100);
}

Resources

  • assets/ - I/​O benchmarks
  • references/ - Platform guides

More Finance & Trading skills

ponytail-debt logo
Finance & Trading

ponytail-debt

Harvest every `ponytail:` comment in the codebase into a debt ledger, so the deliberate shortcuts and deferrals ponytail leaves behind get tracked instead of rotting into "later means never". One-shot report, changes nothing.

155.5K 27.9K
View
stripe-integration logo
Finance & Trading

stripe-integration

Stripe payment processing with checkout sessions, subscriptions, webhooks, and customer management.

40.2K 12.9K
View

Build comprehensive 3-5 year financial models with revenue projections, cost structures, cash flow analysis, and scenario planning for early-stage startups. Use this skill when creating financial projections, calculating burn rate or runway, modeling fundraising scenarios, or preparing investor-r...

40.2K 12K
View
stock-analysis logo
Finance & Trading

stock-analysis

Stock and cryptocurrency analysis with portfolio management and multi-dimensional scoring.

46 11.9K
View
coinglass logo
Finance & Trading

coinglass

Real-time crypto derivatives positioning, whale tracking, liquidations, and institutional ETF flows across 37 specialized tools.

27 11.5K
View

Master dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.

40.2K 10.5K
View

Finance AI tools

C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Finalle.ai logo
Finance

Finalle.ai

Stay Ahead with Finalle.ai: The Ultimate Financial News and Tools Platform

Free
View

AI-powered Pine Script code generator for TradingView

Paid
View
TradeUI logo
Finance

TradeUI

Empower your investment strategies with AI signals, option flow data, and advanced chart patterns.

Paid
View
D
Finance

Danelfin

Danelfin review covering its AI stock and ETF scores, rankings, portfolio tools, current pricing, strengths, risks, and alternatives for investors.

Freemium
View
E
Finance

Ellisense

A software for comprehensive market sentiment analysis.

Paid
View

'Stock Correlations' App by Freshly.ai: Reveal Stock Patterns and Trends

Free
View