Skip to content

v0.3.0

Choose a tag to compare

@ehsanmok ehsanmok released this 19 Apr 15:03
· 1256 commits to main since this release

flare v0.3.0 cuts over to a single-threaded reactor architecture. The HTTP
server goes from ~50K req/s blocking to ~140-157K req/s on an event loop,
and the new flare.runtime subpackage exposes the reactor primitives
(Reactor, Event, TimerWheel) so you can build other protocols on the
same foundation.

Public API is byte-for-byte compatible with v0.2.0. HttpServer.bind() +
srv.serve(handler) just works, only now under a kqueue/epoll loop.

Headline

  • Single-threaded reactor HTTP server (kqueue on macOS, epoll on Linux).
    On Linux AWS EPYC: on par with single-worker nginx and ~2x Go's
    net/http. On Apple M-series: ~1.1x Go's net/http. Measured with
    the standard TFB plaintext test, GOMAXPROCS=1 and worker_processes 1.
  • 375 tests and 15 fuzz harnesses (over a million fuzz runs, zero
    known crashes).
  • Four new examples for UDP, TLS, cookies, and direct reactor usage.
  • Pinned toolchain for reproducibility: Mojo 0.26.3.0.dev2026041805 +
    json v0.1.2 (both built by the same compiler).

Benchmarks

macOS, Apple M-series, single-threaded, wrk -t1 -c64 -d30s, 5-run
median of middle 3 with stdev ≤ 3%.

Server Req/s (median) p50 p99 vs Go net/http
flare (reactor) 157,459 0.39 ms 0.80 ms 1.10x
Go net/http (1 thread) 143,500 0.44 ms 0.86 ms 1.00x

Linux, AWS EPYC 7R32 (64 vCPU).

Server Req/s (median) p50 p99 vs Go net/http
nginx (1 worker) 81,612 0.40 ms 0.79 ms 2.00x
flare (reactor) 79,965 0.78 ms 1.53 ms 1.96x
Go net/http (1 thread) 40,739 1.59 ms 3.10 ms 1.00x

Reproduce locally:

pixi run --environment bench bench-vs-baseline-quick   # flare vs Go, ~7 min
pixi run --environment bench bench-vs-baseline         # + nginx, + latency floor

See the README benchmarks section
for the full methodology (integrity check, pinned toolchains, warmup
protocol, per-run provenance dir).

What's new since v0.2.0

flare.runtime (new subpackage)

  • Reactor — uniform API over kqueue (macOS) and epoll (Linux),
    dispatched at compile time. Register fds with a token and interest
    bits, poll for readiness, wake from another thread.
  • TimerWheel — hashed timing wheel (512 slots + overflow) with O(1)
    schedule / cancel. Used for per-connection idle timeouts.
  • Event + INTEREST_READ / INTEREST_WRITE / EVENT_READABLE /
    EVENT_WRITABLE / EVENT_ERROR / EVENT_HUP / WAKEUP_TOKEN.

flare.http.HttpServer (rewritten)

  • Event loop replaces the blocking _handle_connection_buffered path.
    Old code fully removed. Public API unchanged: every existing
    test_server.mojo test passes without modification.
  • Per-connection state machine in flare/http/_server_reactor_impl.mojo:
    READING → WRITING → keep-alive loop → CLOSING.
  • Configurable idle_timeout_ms, write_timeout_ms,
    shutdown_timeout_ms per connection; hashed timing wheel enforces
    them without extra syscalls per request.
  • Graceful shutdown: HttpServer.close() stops accepting new
    connections and drains in-flight ones up to shutdown_timeout_ms.

Parser and serialiser cleanup

  • _read_line_buf: single-scan plus one-shot String(unsafe_from_utf8=...)
    construction instead of the per-byte line += chr(...) loop.
    Biggest single throughput win.
  • _is_content_length / _is_connection: inline case-insensitive
    byte compare, avoiding the per-header _ascii_lower allocation.
  • _ascii_lower / _lower / _append_str: bulk write through
    pre-sized buffers, memcpy replaces per-byte loops everywhere.
  • _ascii_strip_slice: single-allocation strip replacing the
    String(String(...)).strip() triple per header value.

New examples (all runnable via pixi run example-<name>)

  • 11_udp.mojo — UdpSocket.bind + send_to + recv_from round
    trip, plus DatagramTooLarge.
  • 12_tls.mojo — TlsConfig, TlsStream.connect to a real HTTPS
    endpoint, raw TLS handshake + minimal HTTP/1.0 GET, plus the
    TlsVerify.NONE escape hatch.
  • 13_cookies.mojo — Cookie, CookieJar, parse_cookie_header
    (client side), parse_set_cookie_header (server side) with
    Max-Age, Path, Secure attributes.
  • 14_reactor.mojo — direct flare.runtime.Reactor usage so you
    can build non-HTTP protocols on the same event loop.

Rigorous benchmark harness

  • pixi run --environment bench bench-vs-baseline orchestrates
    integrity check + 5-run measurement across flare, Go net/http,
    nginx. 3% stdev gate, full env capture per run, TFB plaintext
    workload.
  • Go and nginx versions pinned via [feature.bench.dependencies] in
    pixi.toml so the comparison cannot drift silently.

Fuzz surface

  • New harnesses: fuzz-reactor-churn (reactor register/modify/
    unregister/poll churn, 200K runs), fuzz-server-reactor-chunks
    (random HTTP-ish bytes fed to the state machine, 30K runs),
    prop-timer-wheel (property test for the timing wheel, 100K runs).
  • Existing harnesses unchanged, all still at 0 crashes.

Packaging and tooling

  • Pixi environments layered: default (lean, runtime only),
    dev (+ mojodoc, pre-commit), fuzz (+ mozz), bench
    (+ Go, nginx, wrk).
  • pixi run format moved behind -e dev so the lean default env
    stays small for users and CI.
  • json dep pinned to tag = "v0.1.2", both sides built against
    Mojo 0.26.3.0.dev2026041805. Same pin in recipe.yaml for
    rattler-build consumers.

Upgrading from v0.2.0

Your code does not need to change. The public API is the same. If you
had tag = "v0.2.0" in pixi.toml, bump to tag = "v0.3.0":

[dependencies]
flare = { git = "https://github.com/ehsanmok/flare.git", tag = "v0.3.0" }

Then pixi install. You're on the reactor.

Known caveats

  • nginx baseline on macOS is still flaky. The pinned nginx config
    occasionally fails to come up under macOS Pixi; the harness reports
    the row as broken when it happens. The Go baseline is reliable on
    both platforms and is the authoritative comparison. Linux nginx is
    stable.
  • Linux numbers in the README footnote are un-pinned wrk / server
    processes on a 64-vCPU EPYC instance
    , so absolute req/s is
    microarchitecture-dependent. Intra-platform ratios (flare vs Go,
    flare vs nginx) are the apples-to-apples comparison, not the cross-
    platform req/s.
  • HTTP/2 is not here yet. Scheduled for v0.4.0 alongside
    thread-per-core (SO_REUSEPORT). See the development notes for the
    v0.4.0 scope.

Commit range

v0.2.0...v0.3.0
is about 30 atomic commits covering the whole reactor migration:
epoll / kqueue / eventfd / pipe FFI, the flare.runtime.Reactor and
TimerWheel abstractions, the per-connection state machine, the
hard replacement of HttpServer, the rigorous benchmark harness, and
the parser / serialiser allocation cleanup.

Thanks for reading. If you hit anything weird, open an issue with
your pixi info output and the exact command that broke.