Threads need to spool up to run in parallel
D-Nice opened this issue · 2 comments
As mentioned in this issue #114 , I see that threads initially run sequentially, and then after a certain number, seem to run in parallel as is expected. This of course causes a performance hit, and seems to favour running lower threads/workers, which spool up faster, than more threads. Any workaround to this?
I would love to see the code used in #114 - there should be no reason to code to run sequentially...
I was able to offset some of the spooling and starting of workers sequentially, by getting rid of the loop in parallel.js that initially starts them sequentially, and instead, create additional threads, in the done callback of the worker, so that existing workers aren't just paused with no work. Still not the most ideal, the best case fix would be to have persistent workers, that just wait on jobs, so no spooling is required.
I don't know if this may be a Windows-specific issue, but child_proccess.fork() seems to take at least 1000ms to run, and since the whole starting of workers runs synchronously, any existing workers, with no work, are just paused, until all workers have started. As I mentioned, best case would be to have persistent workers, that could be started with an init call, and with the persistent optioin, once jobs are completed, the workers wouldn't terminate, but would just wait for new work to be assigned.