Most sincere salutations,
I’m happy to announce the release of moonpool 0.1. Moonpool, so far, is mostly an experiment, but is in a usable state already.
So what is moonpool? It’s my go at starting to leverage OCaml 5 for multicore computations. Unlike other approaches, it relies heavily on classic Thread.t
, because unlike domains it’s ok to create many of them and have some block on IO or long running C calls. A pool provides a run: (unit -> unit) -> unit
function that runs the task (its argument) onto one of the pool’s workers at a later date.
Moonpool works by allocating, at startup, a fixed pool of domains, of the recommended size.[1] From there, the user can create a number of regular thread pools, each of which will be distributed over the pool of domains so that the threads can run in parallel. It’s perfectly possible to have, on a 16 core machine, a pool of 50 IO threads for some server, along with a pool of 16 compute threads.
Moonpool also provides a Future abstraction. These futures are thread safe; the combinators such as map
, bind
, etc. can themselves run on pools. Futures are quite lightweight and use an Atomic.t
variable for storage, no lock needed.[2]
Lastly: moonpool also works on OCaml >= 4.08, by simply reducing to regular thread pools running on a single domain. This should allow users to use moonpool on 4.xx, before migrating to 5.xx on their own time.
Documentation is here. It’s released under the MIT license.
Contributions or discussions are very welcome. This is very early days for this project, and I have lots to learn. The task scheduler is quite simple and will probably not compete with domainslib on super-fine grained tasks; but for use cases where tasks are not that tiny I think it works perfectly fine already.