-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure stats are always consistent when handling a task result #411
Comments
Thanks for reporting. How can we reproduce your issue? |
This example reproduces the issue: package.json
index.js
worker.js
The output I get is the following:
I would expect to have a Correction: from this output I noticed that during the first "run" all workers are working as expected. |
Thanks for sharing this code, I can reproduce your output. To check whether all workers are busy, you can calculate how long it should take to execute all tasks (100 * 1 sec / 8 workers = 12.5 sec), and measure how long it actually takes, that is indeed 12.5 sec and a little bit extra (time is needed to spin up 8 workers). What's going on here that you log the statistics right after a task finished, and before a new task is started. Therefore you see 7 workers busy instead of 8. Only the first round things work a bit different: apparently in that case the stats come in when the worker is already marked busy on the next target. This could be related on the order of to two callbacks listening on the same Promise: your callback, and the callback of the workerpool that will start a next task. It would be nice to make this work consistent, if anyone is interested to look into this please let me know. To "solve" your issue, you can change .then(checkCompleted) to: .then(() => setTimeout(checkCompleted)) Then you'll always see 8 workers busy. |
Thanks @josdejong, your explanation makes total sense. Unfortunately at the moment I don't have the time to investigate the consistency issue with the callbacks but feel free to leave the issue open some someone else may look into it. |
👍 I'll adjust the title. |
Hi, thank you for this great library.
I'm using it with the following syntax:
During execution of a loop, I check
pool.stats()
and I get the following output:One worker is always idle. Am I doing something wrong?
The text was updated successfully, but these errors were encountered: