Skip to content

epoll backend: per-fd completion delivery, two-buffer readv, no hold limit - #32

Merged
y001j merged 1 commit into
masterfrom
perf/epoll-backend
Nov 22, 2026
Merged

y001j merged 1 commit into
masterfrom
perf/epoll-backend

Conversation

@y001j

@y001j y001j commented Nov 22, 2026

Copy link
Copy Markdown
Owner

The epoll backend issued the same syscalls per request as the hand-written epoll server in bench/ but reached only 0.64–0.81x of its throughput. Profiling (perf, syscall tracepoints) found three causes:

  1. Batch-then-deliver: it read every fd of an epoll_wait batch (~20) before running any completion, so the first reply waited for all other reads. With request/response traffic that costs throughput — the server even idled ~5%. Completions now run after each fd's events (still after the submitting call returns, as with io_uring).
  2. Extra read: a message exactly filling a buffer cost a second read returning EAGAIN (2 reads/request at 16KB). recv now uses readv into two buffers: an empty second buffer means drained; two full ones mean more is waiting. (Reading only once per event fixed this but hurt pipelined 16KB by ~20%, so it was not kept.)
  3. Hold limit: in-place sends were limited to half the buffers (as for io_uring), forcing 16KB copies at 512 connections (5% memmove). The epoll pool is ours and sends usually complete in the same iteration, so all buffers may be held.

Throughput vs the hand-written loop (server on 1 core, 16 scenarios, 3 rounds):

before after
median 0.83 0.94
128B, 16–64 conns 0.71–0.81 0.92–0.99
16KB, 512 conns 0.64 0.83
16KB pipelined, 16/64/512 conns 1.14 / 1.10 / 0.96 1.41 / 1.22 / 1.62

The whole suite passes on both backends (-race), plus stress/fuzz seeds 3×; staticcheck clean. README, architecture doc and changelog (Unreleased) updated.

🤖 Generated with Claude Code

…limit

Profiling the epoll backend against the hand-written epoll server in
bench/ (same syscalls per request, but 0.64-0.81x throughput) found:

- It read every fd of an epoll_wait batch before running any
  completion, so the first connection's reply waited for all the other
  reads: with request/response traffic that costs throughput, and the
  server even idled. Completions now run after each fd's events.
- A message that exactly fills a buffer cost a second read returning
  EAGAIN (2 reads per request at 16KB). recv now uses readv into two
  buffers: an empty second buffer means the socket is drained, and two
  full ones mean more data is waiting.
- In-place sends were limited to half the buffers, as for io_uring, so
  at 512 connections later replies were copied (5% memmove). The epoll
  pool is ours and sends usually complete in the same iteration, so all
  buffers may now be held.

Against the hand-written loop (server on 1 core, 16 scenarios): median
0.83x -> 0.94x; small messages at 16-64 connections 0.71-0.81x ->
0.92-0.99x; pipelined 16KB 0.96-1.14x -> 1.22-1.62x.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.44%. Comparing base (43c3288) to head (22d15e4).

Files with missing lines Patch % Lines
epoll.go 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #32      +/-   ##
==========================================
+ Coverage   70.27%   70.44%   +0.16%     
==========================================
  Files          25       25              
  Lines        2335     2355      +20     
==========================================
+ Hits         1641     1659      +18     
- Misses        694      696       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@y001j
y001j merged commit 3533385 into master Nov 22, 2026
6 checks passed
@y001j
y001j deleted the perf/epoll-backend branch November 22, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant