Eio provides an effects-based direct-style IO stack for OCaml 5.0. It aims to be easy to use, secure, well documented, and fast. It consists of a generic cross-platform API, plus optimised backends for different platforms.
This 0.1 release is for early adopters to try it out and provide feedback. It works with OCaml 5.00.0+trunk at the time of writing, but as that is a moving target we suggest using 4.12.0+domains for now:
opam switch create 4.12.0+domains --repositories=multicore=git+https://github.com/ocaml-multicore/multicore-opam.git,default
opam install eio_main
There is a tutorial giving a tour of the main features:
- Concurrent code without a need for monads or special syntax: no more
>>=
,let%lwt
,Lwt_list.iter_s
, etc. Just use plain OCaml code (|>
,let
,List.iter
). - Concurrency primitives (promises, streams, semaphores), as usual.
- Run multiple fibres on a single core, or distribute work across multiple CPUs.
- Replace any OS features (files, networks, clocks, etc) with mocks for testing.
- Structured concurrency, to prevent leaking resources (such as open file descriptors or fibres).
- Automatic handling of cancellation, so that if one part of your program fails then other fibres are cancelled automatically until the exception is handled or the program exits with a stack trace.
- Capability-based security. For example, a
Dir.t
only grants access within some sub-tree of the filesystem, and prevents escaping it using..
or by following symlinks out of the tree.
Various libraries are in the process of being ported to Eio. Examples include a Gemini client (including ports of angstrom, notty and ocaml-tls), and Dream (providing a direct-style API to users while using lwt-eio internally to integrate with existing libraries).
Performance seems good, especially on recent versions of Linux were Eio can take advantage of io_uring. For example, this graph shows how various HTTP servers cope with increasing load:
httpaf_eio
is currently at the top (though note that the Rust server, rust_hyper, is not using io_uring, so this is not a completely fair comparison).
Useful resources:
- Eio â the main project
- Lwt_eio â integration with or porting from Lwt
- awesome-multicore-ocaml â list of multicore resources
Feedback, and PRs adding missing features, are welcome!