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

Shuffle glob queues per env flag #1586

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ermanc
Copy link

@ermanc ermanc commented Oct 19, 2017

Allows developers the option to have shuffling * queue processing via ENV['SHUFFLE'].

The reasoning behind is two fold:

  1. As mentioned by @steveklabnik in Shuffling queues on * #1075 (comment), * processing kind of implies lack of explicit prioritization. If you really care about certain prioritization to be maintained, explicit queue lists are suited.

  2. Alphabetical prioritization means queues that are processed by general * workers are more prone to having one obnoxious queue (on purpose or accidentally) effectively block others just because they are higher up alphabetically. Using shuffling, an obnoxious queue cannot block or even slow down other queues as all have statistically similar chances of being processed every turn.

Usage is non-default, so the default behavior is still sorted * queues.

Feature is enabled via SHUFFLE=true QUEUE=* rake resque:work

@coveralls
Copy link

coveralls commented Oct 19, 2017

Coverage Status

Coverage increased (+0.03%) to 83.345% when pulling 1a58503 on ermanc:shuffle_glob_queues_per_env_flag into f54466f on resque:master.

@ermanc ermanc force-pushed the shuffle_glob_queues_per_env_flag branch from 1a58503 to 7a2a151 Compare October 19, 2017 17:59
@coveralls
Copy link

coveralls commented Oct 19, 2017

Coverage Status

Coverage increased (+0.03%) to 83.345% when pulling 7a2a151 on ermanc:shuffle_glob_queues_per_env_flag into f54466f on resque:master.


# Queues should not have been processed in sorted order
assert all_queues.sort != processed_queues
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This is cool. My only concern is that the test is quite complex. Since the guts of the change is using shuffle instead of sort how about trying to test #glob_match in isolation instead? Is that possible?

Copy link
Author

Choose a reason for hiding this comment

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

It's possible but I personally prefer the current spec as it demonstrates the purpose and usage like the other specs here. It's also very loosely coupled to implementation.

@gerardc
Copy link
Contributor

gerardc commented Oct 23, 2017 via email

end

# Queues should not have been processed in sorted order
assert all_queues.sort != processed_queues
Copy link
Member

Choose a reason for hiding this comment

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

Even that it is small I think there is a chance that the shuffled array will be the same as the sorted array right? Would not this test be broken in that case?

Copy link
Author

Choose a reason for hiding this comment

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

There is a chance the shuffled array will be the same as the sorted array, yes. I'm more confident in a test case that tests the observable effect rather than implementation (e.g. spying on the sort vs shuffle call) and I cannot think of another way to test the "shuffled" outcome other than it being not sorted.

I certainly welcome any suggestions on a better testing strategy, as I find this an interesting behavior to test for.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. I think the comment with the probability is good enough for that.

Copy link
Contributor

@jeremy jeremy left a comment

Choose a reason for hiding this comment

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

The SHUFFLE env var suggests that the queue list is shuffled, or that all jobs are somehow shuffled. Can we be clear that it's shuffling the queues matched by the wildcard glob?

end.sort
end

if ENV['SHUFFLE'] && ENV['SHUFFLE'] != 'false'
Copy link
Contributor

Choose a reason for hiding this comment

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

Set up wildcard glob sort/shuffle behavior in #initialize

Copy link
Contributor

Choose a reason for hiding this comment

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

What do think of making this a little more forgiving?

Suggested change
if ENV['SHUFFLE'] && ENV['SHUFFLE'] != 'false'
if ENV['SHUFFLE'] && ENV['SHUFFLE'].downcase != 'false'

@jrochkind
Copy link
Contributor

i am interested in this, for reasons explained in PR description at top.

Is there any hope for it? Anything I can do to help bring it home?

Copy link
Contributor

@iloveitaly iloveitaly left a comment

Choose a reason for hiding this comment

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

This is a very old PR, but still a great change! Thanks for the contribution. I've slowly been going through old PRs since I've been added as a contributor.

@ermanc if there's still interest in getting this merged, could you:

  • Rebase on master and make sure tests are passing
  • Add some docs to the readme about how this works

Also, if someone else wants to pick this up (@jrochkind) that's great too!

end.sort
end

if ENV['SHUFFLE'] && ENV['SHUFFLE'] != 'false'
Copy link
Contributor

Choose a reason for hiding this comment

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

What do think of making this a little more forgiving?

Suggested change
if ENV['SHUFFLE'] && ENV['SHUFFLE'] != 'false'
if ENV['SHUFFLE'] && ENV['SHUFFLE'].downcase != 'false'

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.

None yet

8 participants