-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
The atomic macro's extra connection can exhaust thread pools #135
Comments
Hi Gary, What makes you think that May help to see what change you've made. Also, have you seen issue #127? Hoping to cut a release for that later today. Seems like the problem you're seeing may be related? |
Atomic itself does not used nested I saw #127 and therefore did a few tests with the |
|
The body supplied to To demonstrate the problem I created this commit which logs connection pool activity, and then added a In the results below, you can see two connections being acquired in the case where the pool is large enough (2), and the execution hangs trying to acquire the second connection in the case where the pool is not large enough (1). Pool Size 2
Pool Size 1
|
The potential fix I mentioned uses a dynamic var to keep track of the connection for the scope of the My issue-135-patched contains that fixed merged into the
|
Hey Gary, thanks a lot for the additional info - that helps! Will try clarify a few things:
The
There are indeed reasons to use
So this is actually the fault of
This is something I hadn't considered, thanks for bringing it to my attention. It's definitely a bug. I might also suggest bumping your pool size btw. Even without the 2 conns/thread, worker threads poll (block) by design - so you'll too easily end up connection starved unless your pool limit is >> your worker thread count. |
Thanks Peter! I think all of this makes sense. I hadn't studied It's definitely also helpful to know that the pool size should be greater than the thread count. I had always figured that was probably a good idea, but not strictly necessary. Thanks again. |
That should have been a safe assumption ;-) Have cut a v2.11.1 release: https://github.com/ptaoussanis/carmine/releases - would you mind confirming that it solves your issue? Thanks again for the report, cheers! :-) |
2.11.1 looks to have fixed the problem, thanks! |
Great, thanks for the confirmation. |
Intentionally or unintentionally (I can't tell) the way that the
atomic
macro ends up expanding to nestedwcar
calls means that any use ofatomic
will require at least two connections from the pool.This doesn't sound terrible, but it can have racey effects when using message queue workers whenever there are more workers than the connections in the pool: as many workers as possible acquire their first connection until the pool is exhausted, and then they all block trying to acquire their second connection.
I tweaked the
wcar
macro to reuse its connection for nested calls, and this caused my tests to pass. I can't seem to successfully run the carmine test suite so I can't verify that it passes as well.I don't understand the carmine codebase well enough to guess whether this is a satisfactory solution (e.g., is it important for some reason that there be a separate connection used for atomic things?). If it is, I can prepare a PR.
Otherwise, should we add a warning to the message queue docs about the pool size? Or is there another approach to solving the problem?
The text was updated successfully, but these errors were encountered: