Open abhijpes opened 1 year ago
This is incorrect as you cannot determine whether the worker will consume from runnableCh or exit channel.
If both - runnableCh and exit has messages on the channel, the runtime is free to choose to pick up from any of the 2 channels. If this worker has been told to exit, it should (at best) finish off this task and exit immediately.
Couldn't start a code review on this github repo, hence adding a few feedbacks here:
The order in which the runnable will be assigned to the goroutine (aka worker) is non-deterministic / depends on the order in which goroutines are scheduled, which will result in imbalance of load (not good as we scale and go to higher request rate).
"numWrkrs" is not being tracked properly. When a worker gets shutdown, numWrkrs should decrement.
The exit channel is an unbuffered channel with "numWrkrs" receivers listening on this channel. Pushing onto an unbuffered channel is a blocking call unless there is at least 1 receiver ready to receive. What if all workers are busy? We will be unblocked only as soon as the first worker gets done with its job, followed by the second worker, followed by 3rd...
So, time that this loop will take to run = Summation of duration of all tasks current running across all workers. Solution - Just close() the runnableCh which will be broadcasted to all workers.