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

Use Queue in memory backend #92

Closed
wants to merge 3 commits into from

Conversation

grantr
Copy link
Collaborator

@grantr grantr commented Oct 3, 2014

Not sure if this is an improvement or not, but it was easy to try. Popping an empty queue now requires exception handling, so there might be a performance degradation. If so it's probably not worth the change.

Queue is more likely to behave correctly when threads are involved.
Default Queue#pop is blocking, but use nonblocking here to preserve
nonblocking semantics.
Keeping the nil check anyway to preserve existing behavior.
rescue ThreadError => e
unless e.message =~ /queue empty/
raise e
end
Copy link
Owner

Choose a reason for hiding this comment

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

Could this use #empty? to avoid the exception?

@bkeepers
Copy link
Owner

bkeepers commented Oct 3, 2014

Is thread-safety the primary motivation for this?

Avoids constant exception/rescue on an idle queue.
@grantr
Copy link
Collaborator Author

grantr commented Oct 3, 2014

Thread safety is the only motivation for this. I can't imagine it will be faster. If you're confident in the current thread-safe-ness, I don't see a good reason to merge.

Starting to seem like a worse idea all the time! 😉

@bkeepers
Copy link
Owner

bkeepers commented Oct 3, 2014

Looks like the code already uses a Monitor, which should make it threadsafe.

@bkeepers bkeepers closed this Oct 3, 2014
@bkeepers
Copy link
Owner

bkeepers commented Oct 3, 2014

oops, didn't mean to close.

@bkeepers bkeepers reopened this Oct 3, 2014
@grantr grantr closed this Oct 3, 2014
@grantr
Copy link
Collaborator Author

grantr commented Oct 3, 2014

Monitor should be fine.

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

Successfully merging this pull request may close these issues.

2 participants