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
Nested groups hang #56
Comments
Hey @koenbok! I'm afraid nested groups will not work with that setup, since it's reusing the same worker pool for both group levels (A and B). Each worker pool receives submitted tasks via a single channel and these are grabbed by worker goroutines in a FIFO manner.
To simplify this exercise, lets assume the max number of workers in the pool is 2, although the same thing can happen with larger pool sizes. Possible workaroundOne possible workaround would be to have a dedicated worker pool for each task level (A vs B). It would look something like this: poolA := pond.New(16, 1_000_000)
poolB := pond.New(16, 1_000_000) // You can tweak these parameters as needed
groupA := poolA.Group()
for i := 0; i < 100; i++ {
groupA.Submit(func() {
fmt.Println("A", i)
groupB := poolB.Group()
for i := 0; i < 10; i++ {
groupB.Submit(func() {
fmt.Println("B", i)
})
}
groupB.Wait()
})
}
groupA.Wait() Given that each pool will have its own FIFO queue, there shouldn't be any deadlock here 🙂 I hope you find this helpful and please feel free to submit pull requests with improvements to the docs if you want, that would be really appreciated 🙏 and it could help others that came across this use case. |
I ran into an issue where a nested group just started to hang, but it seems to really depend on the amount of workers and tasks. My expectation was that this should work, especially because the initially smaller amounts of tasks worked fine.
(If you lower the n=100 to n=10 it does work on my MacBook Pro M3)
Is this a bug or can I help document this better?
The text was updated successfully, but these errors were encountered: