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

consumer: redistribute RDY when connections are active #208

Merged
merged 2 commits into from
Jun 3, 2017

Conversation

mreiferson
Copy link
Member

fixes #179

@mreiferson mreiferson added the bug label Apr 16, 2017
@mreiferson
Copy link
Member Author

RFR @jehiah @judwhite @ploxiln

This is one simple way to address #179 by bounding the time a consumer will stay pinned to any producing nsqd, regardless of last message delivery.

LowRdyIdleTimeout time.Duration `opt:"low_rdy_idle_timeout" min:"1s" max:"5m" default:"10s"`

// Duration to wait until redistributing RDY for an nsqd regardless of LowRdyIdleTimeout
LowRdyTimeout time.Duration `opt:"low_rdy_timeout" min:"1s" max:"5m" default:"30s"`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably never be lower than LowRdyIdleTimeout, I can enforce this...

@ploxiln
Copy link
Member

ploxiln commented Apr 16, 2017

Looks good to me.

I noticed this part below seems less than optimal (abbreviated):

 	for len(possibleConns) > 0 && availableMaxInFlight > 0 {
 		availableMaxInFlight--
 		i := r.rng.Int() % len(possibleConns)
 		c := possibleConns[i]
 		possibleConns = append(possibleConns[:i], possibleConns[i+1:]...)
 		r.updateRDY(c, 1)
}

All conns are added to possibleConns, so it's quite possible that some of them already have non-zero ready count. So some of availableMaxInFlight will end up not actually distributed. (But this problem will probably fix itself in later redistributions. And it's not new.)

This could be fixed by appending to possibleConns only if the conn has a zero ready count.

@mreiferson
Copy link
Member Author

All conns are added to possibleConns, so it's quite possible that some of them already have non-zero ready count. So some of availableMaxInFlight will end up not actually distributed.

Hmm, yea, can probably be improved, but it's at least randomized.

@mreiferson
Copy link
Member Author

@ploxiln want to gimme a 👍 — also, there are probably a few lessons to learn from nsqio/pynsq#179 and nsqio/pynsq#176

@ploxiln
Copy link
Member

ploxiln commented Jun 3, 2017

👍 to these additions.

... but the existing rdyCount logic is a bit tricky, and I'm not really familiar with it, and it's taking a while to digest. Anyway, I'm confident that this is strictly an improvement. fwiw :)

@mreiferson mreiferson merged commit 3c0361b into nsqio:master Jun 3, 2017
@mreiferson mreiferson deleted the active-redistribute branch June 3, 2017 15:56
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.

consumer: redistributeRDY fails when connection remains active
2 participants