-
Notifications
You must be signed in to change notification settings - Fork 127
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
reader: make sure RDY is updated when connection count changes #183
reader: make sure RDY is updated when connection count changes #183
Conversation
316ce71
to
cc9c9c7
Compare
@mreiferson RFR |
cc9c9c7
to
1060235
Compare
nsq/reader.py
Outdated
# Preexisting connections might be using all possible RDY, preventing us | ||
# from sending RDY 1 on the new connection. In that case, we force a | ||
# preexisting connection to update RDY to the new, lower connection_max_in_flight. | ||
self._maybe_update_rdy(preexisting_conns[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to always choose the 0th conn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right that it's not safe. We need to guarantee that the conn we select has RDY
greater than the new connection_max_in_flight()
. One can be shown to exist at this point, on the assumption that we're not in the abnormal regime where the connection count, counting the new conn, is greater than max_in_flight
, but we're not guaranteed that an arbitrarily chosen conn satisfies that condition. (If we are in the abnormal regime, trying to set a non-zero RDY
on the new conn is going to fail and we have to rely on periodic redistribution to give RDY
to the new conn.)
Just resetting RDY
on all the connections, as you suggest, would simplify the logic.
Thinking out loud — is it easier to just reset all conn RDY counts whenever we process a new connection? Rather than this odd separation between initial RDY and then proper per-conn max_in_flight after receipt of first message? |
I did try that out. But test expectations need to be changed if we do that, so instead I went with a change that involved less perturbation to current behavior. Happy to go either way. |
1060235
to
2444db5
Compare
2444db5
to
933227b
Compare
I think we don't want to unconditionally reset RDY counts on the other connections: some might be be testing the waters with RDY 1 and waiting for a message, so it would be wrong to update them to the connection max-in-flight. But it would work to update RDY on all connections that have RDY greater than the new per-connection max. With that additional condition, we also don't need any test changes. PR updated accordingly. |
Sorry for the delay, I think this looks good. Is there a relatively easy test we can add that fails on |
It's straightforward to test, but requires multiple connections, so there's not a natural place to add the test. One option would be to refactor the integration test harness in |
Let's try that! Thanks! |
3c6c3ff
to
bfbadb1
Compare
bfbadb1
to
1527270
Compare
@mreiferson Added the new test file. Sorry for the delay. I moved some helper functions from |
awesome, thanks! |
What about 0.8.2 release with fixed #182 ? |
Fixes #182.
Previously, a connection's
rdy
attribute was decremented on message receipt; when it dipped low enough the connection would send a newRDY
count of_connection_max_in_flight()
. One consequence of this was that, when_connection_max_in_flight()
changed (because either the connection count or the reader'smax_in_flight
attribute changed), each connection would eventually update to the new value.The reader's
total_rdy
attribute was also decremented on message receipt. This guaranteed (under the assumption that some connection was receiving messages), thattotal_rdy
would drop belowmax_in_flight
, freeing up space for a new connection to send an initialRDY
count of 1.Now that these client-side attributes aren't updated with each message received, these two cases need to be catered for explicitly.