Skip to content
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

Merged
merged 2 commits into from
Jun 25, 2017

Conversation

alpaker
Copy link
Contributor

@alpaker alpaker commented Jun 5, 2017

Fixes #182.

Previously, a connection's rdy attribute was decremented on message receipt; when it dipped low enough the connection would send a new RDY 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's max_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), that total_rdy would drop below max_in_flight, freeing up space for a new connection to send an initial RDY 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.

@alpaker alpaker closed this Jun 5, 2017
@alpaker alpaker reopened this Jun 6, 2017
@alpaker alpaker force-pushed the create-margin-for-new-conn-rdy branch from 316ce71 to cc9c9c7 Compare June 6, 2017 04:01
@alpaker
Copy link
Contributor Author

alpaker commented Jun 6, 2017

@mreiferson RFR

@alpaker alpaker changed the title make sure per-connection RDY counts are updated when connection count changes make sure client-side RDY counts are updated when connection count changes Jun 6, 2017
@alpaker alpaker changed the title make sure client-side RDY counts are updated when connection count changes make sure client-side rdy attributes are updated when connection count changes Jun 6, 2017
@alpaker alpaker force-pushed the create-margin-for-new-conn-rdy branch from cc9c9c7 to 1060235 Compare June 6, 2017 04:40
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])
Copy link
Member

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?

Copy link
Contributor Author

@alpaker alpaker Jun 6, 2017

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.

@mreiferson
Copy link
Member

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?

@mreiferson mreiferson added the bug label Jun 6, 2017
@mreiferson mreiferson changed the title make sure client-side rdy attributes are updated when connection count changes reader: make sure client-side rdy attributes are updated when connection count changes Jun 6, 2017
@mreiferson mreiferson changed the title reader: make sure client-side rdy attributes are updated when connection count changes reader: make sure RDY is updated when connection count changes Jun 6, 2017
@alpaker
Copy link
Contributor Author

alpaker commented Jun 6, 2017

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.

@alpaker alpaker force-pushed the create-margin-for-new-conn-rdy branch from 1060235 to 2444db5 Compare June 6, 2017 17:11
@alpaker alpaker force-pushed the create-margin-for-new-conn-rdy branch from 2444db5 to 933227b Compare June 6, 2017 17:12
@alpaker
Copy link
Contributor Author

alpaker commented Jun 6, 2017

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.

@mreiferson
Copy link
Member

Sorry for the delay, I think this looks good.

Is there a relatively easy test we can add that fails on master and is fixed by this?

@alpaker
Copy link
Contributor Author

alpaker commented Jun 12, 2017

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 test_reader.py to work with multiple connections. But a better direction might be to add a new test_rdy.py that can accumulate unit tests related to RDY count management, à la test_backoff.py.

@mreiferson
Copy link
Member

But a better direction might be to add a new test_rdy.py that can accumulate unit tests related to RDY count management, à la test_backoff.py.

Let's try that! Thanks!

@alpaker alpaker force-pushed the create-margin-for-new-conn-rdy branch 6 times, most recently from 3c6c3ff to bfbadb1 Compare June 24, 2017 18:54
@alpaker alpaker force-pushed the create-margin-for-new-conn-rdy branch from bfbadb1 to 1527270 Compare June 24, 2017 19:04
@alpaker
Copy link
Contributor Author

alpaker commented Jun 24, 2017

@mreiferson Added the new test file. Sorry for the delay.

I moved some helper functions from test_backoff.rdy to a new reader_unit_test_helpers.py. Let me know if you don't like that refactoring.

@mreiferson
Copy link
Member

awesome, thanks!

@mreiferson mreiferson merged commit 2d5e2aa into nsqio:master Jun 25, 2017
@smant
Copy link

smant commented Jan 8, 2018

What about 0.8.2 release with fixed #182 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants