This repository was archived by the owner on Nov 22, 2026. It is now read-only.
Repository navigation
mojo-aio v0.1.0
mojo-aio v0.1.0
Released: 2026-11-04 · Commit: 8109105 · Previous: first release
What it does
epoll event loop for Mojo: readiness events, one-shot timers, non-blocking TCP. Callback-free:
wait() fills a list you own with (token, events) and you dispatch, so there is no closure
storage and no allocation per event. 163 lines of code, libc only, Linux.
Same server CPU per request as uvloop, a third of Python asyncio's, half the memory of either
(echo ping-pong, docs/perf.md).
import aio
def main() raises:
var lfd = aio.tcp_listen(0) # 127.0.0.1, a free port
var loop = aio.Loop()
loop.add(lfd, aio.IN, 1)
loop.after(10, 2) # one TIMER event in 10 ms
var evs = List[aio.Event]()
while True:
_ = loop.wait(evs)
for ev in evs:
if ev.events & aio.TIMER:
print("timer", ev.token, "fired; port", aio.local_port(lfd) > 0)
aio.close(lfd)
returnHighlights
- A Mojo network server with uvloop's CPU cost per request and half its memory.
- Timers and sockets in one loop, no callbacks to store.
- Multi-threaded servers: shared epoll set, ONESHOT, per-thread buffers (mojo-bento runs on it).
Changes
Added
Loop(add/modify/remove/after/wait/ready),tcp_listen,local_port,accept,read,write,close.
Verified
| Check | Result |
|---|---|
scripts/check.sh timers |
2000 timers in order, worst 1.2 ms late, wait(20) not early |
scripts/check.sh echo |
10,000 concurrent connections, 446 MB echoed byte for byte |
scripts/check.sh fd leak |
5 fds before, 5 after; a no-close mutant fails with 10005 |
scripts/check.sh negative control |
AIO_BREAK=1 server fails the client |
scripts/check.sh doc |
README block == examples/quickstart.mojo, example runs; drift fails |
scripts/bench.sh |
CPU 4.5 us/req (uvloop 4.5, asyncio 14.8), RSS 11 MB |
mojo-bento scripts/ci.sh on aio |
PASS (b1 to b6) |
Known limits
- Linux x86-64 only (packed 12-byte epoll_event). IPv4 only.
wait()is single-threaded (timer heap); other threads useready().- No io_uring; no TLS. CI workflow has not run on GitHub yet (repo not pushed).
Upgrade / run
mojo run -I path/to/mojo-aio/src app.mojo
Commits
8109105docs: README, design, perf, quickstart example checked by the gatef9aa5e9refactor: epoll_ctl methods take an immutable Loop5b18f8cfeat: host binding, ONESHOT, thread-safe ready(), resilient acceptcbd4f2ffeat: epoll event loop, timers and non-blocking TCP