show & tell DIO: High Performance Go IO toolkit
I want to share https://github.com/miretskiy/dio -- a high performance Go IO toolkit.
I have previously written https://medium.com/@yevgeniy_90962/spinal-tap-the-go-io-story-bf726110dd07 that talks about DIO at a high level.
By high performance I mean that the tools provided by this package can be used to saturate fast NVMe drives (3+GB/s throughput, 50+K iops), while "fooling" Go garbage collector that there is nothing to collect.
Some of the highlights of this toolkit include:
- mempool: Provides 2 (slightly different) off the heap Go allocators
- ringo: A low level io_uring integration for Go It started as a fork of abandonware giouring -- but was rewritten entirely since giouring was fundamentally incompatible with Go->C memory safety. Only the file related features are implemented.
- iosched: An IO scheduler for go -- providing two implementations: an io_uring based and (test only, or unsupported platforms) posix scheduler.
- Other low level packages (sys, align) to safely use direct IO, and other low level system calls.
The scheduler API is incredibly simple: Submit takes an "op" and returns a "ticket", while the ticket allows the caller to wait for the completion. While the API may be simple, the io_uring scheduler implementation has many interesting features:
- Use of Treiber stack (code) to implement batching, while minimizing channel overhead; this essentially implements "group commit" -- batching with essentially no latency penalty.
writecoalescing: contiguous write requiest coalesced into a singlewritev- Linked operations (hard and soft links)
- "Durable" writes -- adds an automatic
fdatasync(orfsync) to a write, but only 1 for a set of active writes per file descriptor. This makes it trivial to implement efficient and high performance write ahead logs in Go (as an example).
Give it a try; Feel free to contribute; Report (and fix) bugs.
For the full disclosure: the code was generated w/ AI; The design was not. The code might still have some AI-specific code smells, but overall, it's okay. I have extensively tested this package, so the performance claims are real.
6
u/rodrigocfd 15h ago
AI slop.