Backlight functions work at the same time
I have CPU intensive functions that I want to run in parallel. What is the concurrency primitive I should be using?
Using agents and futures is not worth it, as the cost of creating a new flow for this process is not justified.
I want to basically run multiple light functions at the same time, without creating threads. Can I do it?
Thank you, Murtaza
source to share
Have you compared the test results?
Agents can be a good solution either way, since they use a fixed size thread pool that is reusable (so you don't constantly create new threads).
I have tested my machine quickly and can make over a million agent calls in 3 seconds:
(def ag (agent 0))
(time (dotimes [i 1000000] (send ag inc)))
=> "Elapsed time: 2882.170586 msecs"
If the agents are still too heavy (unlikely?), Then you should probably look for a way to batch group functions into one unit of work. If you do this, the overhead of concurrency primitives will be minimal.
source to share