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

Better handling of Pool and job reserve for multiple connections #11

Open
nesquena opened this issue Nov 3, 2012 · 5 comments
Open

Comments

@nesquena
Copy link
Member

nesquena commented Nov 3, 2012

There is an issue with the pool concept and then with put and reserve. We should change beaneater_test with https://github.com/beanstalkd/beaneater/blob/master/test/beaneater_test.rb#L6 and test with multiple connections.

The issue is around how reserving works in this case:

@beanstalk = Beaneater::Pool.new(['127.0.0.1:11300', '127.0.0.1:11301'])
@tube = @beanstalk.tubes["foo"]
@tube.put("bar") # <-- put onto connection one
@tube.put("baz") # <-- put onto connection one

So now we have two jobs on connection one. If we now call

@tube.reserve

Reserve could randomly pick connection two in which case there are no jobs and it would hang forever. Also other variations of this problem when 2 jobs fall into one connection and one into another and calling reserve will eventually start to hang up even though the other connection still has jobs.

@nicotaing
Copy link
Member

yeah i see, we should be more smart about it, i think we should stop using transmit_to_rand for reserving jobs.

Cycling through all connections it's neither the best approach, does threading sounds too crazy?

@zdzolton
Copy link

Perhaps an approach to try for the reserve method would be to look at the current-waiting counter (from the stats command) for each connection, distributing the reserve commands across connections. The goal being to avoid starving any particular queue for consumers.

@iros
Copy link

iros commented Jan 7, 2013

Is there any progress on this issue? I'm rather blocked by this implementation as well. I use on average 3 connections and on average about 1/3 of my jobs don't ever run. Seems like doing a round robin until we find a job in a queue or find no jobs is the right way to go on this one... no?

@nesquena
Copy link
Member Author

nesquena commented Jan 7, 2013

Yeah I can think of a several ways to handle this better then we are handling it now. We will tackle this soon although if anyone else wants to take a stab at a pull request, that'd be great.

@nicotaing
Copy link
Member

I'm aware it's not the best way, there's a workaround by setting up a timeout and eventually it will reserve the job on the right tube:

job = @beanstalk.tubes.reserve(5) # 5 seconds

We'll come up with a better way, but let me know if that workaround works for you

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

No branches or pull requests

4 participants