pmonks / embroidery

A Clojure micro-library for leveraging virtual threads on JVMs that support them

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for bounded virtual concurrency

pmonks opened this issue · comments

There are situations where a parallelisable task has limits unrelated to CPU capacity that still place practical limits on how many concurrent virtual threads can be used at once. I/O bound tasks that operate on many tens (or hundreds) of thousands of file and/or socket connections, for example, will be limited by some OSes in how many of those they are allowed to have open at once, and having unlimited virtual concurrency (as is currently the case in embroidery) results in such tasks failing, typically with a java.io.FileNotFoundException: <filename> (Too many open files) (or similar) error.

embroidery should therefore offer an option for callers to specify the upper bound on the number of virtual threads such tasks will use (e.g. via pmap*), while still defaulting to unlimited virtual threads.

Note: determining how many file handles the JVM process can have open simultaneously is difficult (and not possible to determine via core JDK APIs), and it is an explicit non-requirement to solve that problem. Rather, it should be incumbent upon the caller to provide a sensible limit to embroidery, based on whatever factor(s) are relevant to their task, and for embroidery to simply use the provided limit.