No Domain.maximum_domain_count() in the stdlib

If you use more than the recommended number of domains, the performance of the program will probably fall off a sharp cliff – in my tests they sometimes become much slower than using just 1 domain. We haven’t documented that carefully enough and I would like to clarify it in the documentation. I repeat, OCaml domains do not behave as native pthreads as people may be familiar with, they are heavier abstractions.

There are niche use-cases for using a non-resizable array indexed over the number of domains, but as pointed above we don’t know if we want to advertise the existence of a fixed limit, as it may vanish later. In the meantime people who really want to write advanced, low-level code for this should access the runtime internals through C – and accept that they are relying on unstable aspects of the runtime, with no compatibility guarantees.

Another reason to shy away from publishing the maximum number of domains is that it might be prone to misuse by users if not documented very carefully – and again, currently our documentation is not good enough. This might hurt more people than it would help, and is a good reason to take things slow.

@UnixJunkie: If you want to spawn many tasks in parallel, don’t try to spawn many domains. Use a fixed-size domain pool and send the work there. This is what domainslib does explicitly; its a first iteration and I am sure that other designs will be proposed in this space (see eg. idle-domains). Use a domain pool.

6 Likes