Workers staying idle, when pools are used #916
Comments
You are creating a pool of 2 workers. Worker1: Work#0 After assigning Work#0 to Worker1, it pauses for 3 seconds. Hint: |
I see that this is intended behaviour, but still, isn't this sub optimal? With the old |
Personally I agree, that a round robin distrubution might be sub optimal. Personally I would appreciate, if there was a way to extend the Pool class to implement customized distribution algorithms. Implementing my own distribution algorithm, made me aware though, that relying on an "isWorking"-State in a thread environment, is inaccurate. If such a method is provided, you tend to rely on it, but you can not and end up in endless loops, eventually. |
@LuckyFellow the problem with that proposal is unstack(), you can't safely do that and also permit unstacking a worker. |
A possible method to implement this could be to have a central task stack in the |
@dktapps you are familiar with the actual internals and I can sense, that things get tricky there and cause implications / side effects. But I was wondering, if the workers internal stack was a Threaded object, then this should hold true:"Threaded objects, most importantly, provide implicit safety for the programmer; all operations on the object scope are safe." If it holds true, then maybe the worker could internally flag the task, which is going to be executed as "being processed" and all externally callable stack manipulating methods must ignore all tasks on the stack, which are flagged as "being processed". |
I've encountered a strange behavior, and was wondering if this is a bug, or if it is intended this way. I am using the pthread build of
3.2.0 - 7.2 - ts - vc15 - x64
, with php version of7.2.14
.I've expected this code to output:
1 is ready
2 is ready
3 is ready
0 is ready
Instead of this, the output is:
1 is ready
3 is ready
0 is ready
2 is ready
For me, it seems that worker 1, gets assigned job 0, and job 2 at the get go, thus worker 2, after finishing job 1 and 3, just waits, instead of taking over job 2 from worker 1. If job 0 and job 2, both are time consuming operations, this script would run in much more time, then if when worker 2 gets idle, would take over job 2 from worker 1.
If this is the intended behavior, could someone please explain to me why it is done in this manner?
The text was updated successfully, but these errors were encountered: