From 647b90e58c0ef329c77a864f8483bb1e1903a225 Mon Sep 17 00:00:00 2001 From: Jack Veenstra Date: Sun, 4 Nov 2012 21:50:25 -0800 Subject: [PATCH 01/16] Replace call to present? with non-rails equivalent. Also bump the version to 0.1.3. --- lib/resque/plugins/round_robin/round_robin.rb | 4 +++- lib/resque/plugins/round_robin/version.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index f64b210..81312df 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -28,7 +28,9 @@ def queue_depth queuename def should_work_on_queue? queuename return true if @queues.include? '*' # workers with QUEUES=* are special and are not subject to queue depth setting max = DEFAULT_QUEUE_DEPTH - max = ENV["RESQUE_QUEUE_DEPTH"].to_i if ENV["RESQUE_QUEUE_DEPTH"].present? + unless ENV["RESQUE_QUEUE_DEPTH"].nil? || ENV["RESQUE_QUEUE_DEPTH"] == "" + max = ENV["RESQUE_QUEUE_DEPTH"].to_i + end return true if max == 0 # 0 means no limiting cur_depth = queue_depth(queuename) log! "queue #{queuename} depth = #{cur_depth} max = #{max}" diff --git a/lib/resque/plugins/round_robin/version.rb b/lib/resque/plugins/round_robin/version.rb index 4a01661..900bb8d 100644 --- a/lib/resque/plugins/round_robin/version.rb +++ b/lib/resque/plugins/round_robin/version.rb @@ -1,7 +1,7 @@ module Resque module Plugins module RoundRobin - VERSION = "0.1.2" + VERSION = "0.1.3" end end end From 76900384a63b1d5c1bef3d8c1b42d97fbc7dd198 Mon Sep 17 00:00:00 2001 From: Jack Veenstra Date: Sun, 4 Nov 2012 22:09:04 -0800 Subject: [PATCH 02/16] Fair round-robin scheduling of jobs. This fixes a bug with picking jobs fairly when there are some empty queues. For example, suppose queues A, and B are empty, while C and D each have 4 jobs. Before this change, the scheduler would start searching at queue A and eventually pick a job from C. Then it would start searching from B and pick another job from C. Then it would start searching at C and pick a job from C. Finally it would start searching from D and pick a job from D. So the jobs would be executed in the order: C, C, C, D, C, D, D, D. But we would like fair scheduling where the jobs alternate between C and D. To fix this bug, the code starts the next search from the next queue that follows the one from which we took the last job. Also bump the version number to 0.1.4. --- lib/resque/plugins/round_robin/round_robin.rb | 2 ++ lib/resque/plugins/round_robin/version.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index f64b210..d8cc793 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -44,6 +44,8 @@ def reserve_with_round_robin log! "Found job on #{queue}" return job end + # Start the next search at the queue after the one from which we pick a job. + @n += 1 end nil diff --git a/lib/resque/plugins/round_robin/version.rb b/lib/resque/plugins/round_robin/version.rb index 4a01661..b6d7660 100644 --- a/lib/resque/plugins/round_robin/version.rb +++ b/lib/resque/plugins/round_robin/version.rb @@ -1,7 +1,7 @@ module Resque module Plugins module RoundRobin - VERSION = "0.1.2" + VERSION = "0.1.4" end end end From df2a37ad02056d4c9225f1aaf8e4d94742650a28 Mon Sep 17 00:00:00 2001 From: Eddy Kim Date: Sat, 17 Nov 2012 22:36:48 -0800 Subject: [PATCH 03/16] relax dependency on resque --- lib/resque/plugins/round_robin/version.rb | 2 +- resque-round-robin.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/resque/plugins/round_robin/version.rb b/lib/resque/plugins/round_robin/version.rb index 4a01661..900bb8d 100644 --- a/lib/resque/plugins/round_robin/version.rb +++ b/lib/resque/plugins/round_robin/version.rb @@ -1,7 +1,7 @@ module Resque module Plugins module RoundRobin - VERSION = "0.1.2" + VERSION = "0.1.3" end end end diff --git a/resque-round-robin.gemspec b/resque-round-robin.gemspec index 4b6ee2d..a0eb705 100644 --- a/resque-round-robin.gemspec +++ b/resque-round-robin.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |gem| gem.summary = %q{A Resque plugin to modify the worker behavior to pull jobs off queues, round-robin} gem.homepage = "" - gem.add_dependency "resque", "1.19.0" + gem.add_dependency "resque", "~> 1.19" gem.add_dependency "resque-dynamic-queues" gem.add_development_dependency('rspec', '~> 2.5') From d47fcd4dd71e3b895209038d5ada7129dc783557 Mon Sep 17 00:00:00 2001 From: Eddy Kim Date: Mon, 19 Nov 2012 10:07:22 -0800 Subject: [PATCH 04/16] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de6d6e0..9e3b175 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ Resque-round-robin A plugin for Resque that implements round-robin behavior for workers. -resque-dynamic-queues is a pre-requisite, as is Resque 1.19 +resque-dynamic-queues is a pre-requisite, as is Resque 1.19 or higher +(now tested up to 1.21) The standard behavior for Resque workers is to pull a job off a queue, and continue until the queue is empty. Once empty, the worker moves From b62a2e9de8e335988644f5b8ca3c06ec6897d25c Mon Sep 17 00:00:00 2001 From: David Joerg Date: Mon, 10 Dec 2012 14:06:55 -0500 Subject: [PATCH 05/16] reserve configurably returns nil if a named queue has more than a configurable number of jobs in it --- .gitignore | 1 + lib/resque/plugins/round_robin/round_robin.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index d87d4be..d36849b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +*~ diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index ce9948f..53b727e 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -39,6 +39,17 @@ def should_work_on_queue? queuename end def reserve_with_round_robin + + # DJs hack: allow this resque process to watch a named queue + # (python), and if that queue has more than a certain number of + # items on it, then we do nothing. This is a big hack to get + # around the lack of round-robining in pyres. + if ENV["RESQUE_DEPENDENT_ON"].present? + if Resque.size(ENV["RESQUE_DEPENDENT_ON"]) > ENV["RESQUE_DEPENDENT_MAX"] + return nil + end + end + qs = rotated_queues qs.each do |queue| log! "Checking #{queue}" From 6fe6c9ffc9d0af9738e52bc625a29d6954492800 Mon Sep 17 00:00:00 2001 From: David Joerg Date: Mon, 10 Dec 2012 14:13:08 -0500 Subject: [PATCH 06/16] whoops --- lib/resque/plugins/round_robin/round_robin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index 53b727e..7157b41 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -45,7 +45,7 @@ def reserve_with_round_robin # items on it, then we do nothing. This is a big hack to get # around the lack of round-robining in pyres. if ENV["RESQUE_DEPENDENT_ON"].present? - if Resque.size(ENV["RESQUE_DEPENDENT_ON"]) > ENV["RESQUE_DEPENDENT_MAX"] + if Resque.size(ENV["RESQUE_DEPENDENT_ON"]) > ENV["RESQUE_DEPENDENT_MAX"].to_i return nil end end From 09b1fdd0f8ea5b7b08f6de0d4cb3a653bed48258 Mon Sep 17 00:00:00 2001 From: David Joerg Date: Mon, 10 Dec 2012 17:28:16 -0500 Subject: [PATCH 07/16] new hack --- lib/resque/plugins/round_robin/round_robin.rb | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index 7157b41..5f0d065 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -26,6 +26,20 @@ def queue_depth queuename DEFAULT_QUEUE_DEPTH = 0 def should_work_on_queue? queuename + + # megahack :( + # + # tried to use an env variable for a less hacky hack, but i dont + # know how to get env variables into the EY resque daemon, and + # Ive been fighting to get this to round-robining system to work + # for five hours now. If you hate this, you can fix it. + # + if !queuename.to_s.index("replay").nil? + if Resque.size("python") > 2 + return false + end + end + return true if @queues.include? '*' # workers with QUEUES=* are special and are not subject to queue depth setting max = DEFAULT_QUEUE_DEPTH unless ENV["RESQUE_QUEUE_DEPTH"].nil? || ENV["RESQUE_QUEUE_DEPTH"] == "" @@ -40,18 +54,13 @@ def should_work_on_queue? queuename def reserve_with_round_robin - # DJs hack: allow this resque process to watch a named queue - # (python), and if that queue has more than a certain number of - # items on it, then we do nothing. This is a big hack to get - # around the lack of round-robining in pyres. - if ENV["RESQUE_DEPENDENT_ON"].present? - if Resque.size(ENV["RESQUE_DEPENDENT_ON"]) > ENV["RESQUE_DEPENDENT_MAX"].to_i - return nil - end - end - qs = rotated_queues qs.each do |queue| + + if queue.to_s.index("replay") + + end + log! "Checking #{queue}" if should_work_on_queue?(queue) && job = Resque::Job.reserve(queue) log! "Found job on #{queue}" From 23799d2944accf9a2ebb42155dcd554925e87085 Mon Sep 17 00:00:00 2001 From: David Joerg Date: Mon, 10 Dec 2012 17:37:56 -0500 Subject: [PATCH 08/16] more sad hax --- lib/resque/plugins/round_robin/round_robin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index 5f0d065..86f0c15 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -34,7 +34,7 @@ def should_work_on_queue? queuename # Ive been fighting to get this to round-robining system to work # for five hours now. If you hate this, you can fix it. # - if !queuename.to_s.index("replay").nil? + if queuename != 'replay' && !queuename.to_s.index('replay').nil? if Resque.size("python") > 2 return false end From 766d6369e816b0f7458905eafde9c5964b622638 Mon Sep 17 00:00:00 2001 From: David Joerg Date: Mon, 10 Dec 2012 17:42:59 -0500 Subject: [PATCH 09/16] yay more hax --- lib/resque/plugins/round_robin/round_robin.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index 86f0c15..9b4d9de 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -34,7 +34,7 @@ def should_work_on_queue? queuename # Ive been fighting to get this to round-robining system to work # for five hours now. If you hate this, you can fix it. # - if queuename != 'replay' && !queuename.to_s.index('replay').nil? + if queuename.to_s != 'replay' && !queuename.to_s.index('replay').nil? if Resque.size("python") > 2 return false end @@ -56,11 +56,6 @@ def reserve_with_round_robin qs = rotated_queues qs.each do |queue| - - if queue.to_s.index("replay") - - end - log! "Checking #{queue}" if should_work_on_queue?(queue) && job = Resque::Job.reserve(queue) log! "Found job on #{queue}" From 62b48dcf50ef1164ae80ffb4d1f30d81bcf1b3fa Mon Sep 17 00:00:00 2001 From: David Joerg Date: Fri, 14 Dec 2012 13:18:04 -0500 Subject: [PATCH 10/16] replays-high can always get processed regardless of the state of python queue --- lib/resque/plugins/round_robin/round_robin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index 9b4d9de..046b1e5 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -34,7 +34,7 @@ def should_work_on_queue? queuename # Ive been fighting to get this to round-robining system to work # for five hours now. If you hate this, you can fix it. # - if queuename.to_s != 'replay' && !queuename.to_s.index('replay').nil? + unless ['replays', 'replays-high'].include?(queuename.to_s) || queuename.to_s.index('replay').nil? if Resque.size("python") > 2 return false end From 7782bf4d1b69bcdd672df4b28e9b00d09f96857d Mon Sep 17 00:00:00 2001 From: David Joerg Date: Thu, 25 Apr 2013 17:41:34 -0400 Subject: [PATCH 11/16] only round-robin when there is a wildcard queue --- lib/resque/plugins/round_robin/round_robin.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index 046b1e5..a22bfc9 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -52,7 +52,16 @@ def should_work_on_queue? queuename false end + # if any of our queues are wildcarded, then we want to round robin among them + def should_round_robin? + return @srr unless @srr.nil? + @srr = @queues.include? '*' + end + def reserve_with_round_robin + if not should_round_robin? + return reserve_without_round_robin + end qs = rotated_queues qs.each do |queue| From f4437c9aa4c3c3e2e4a172a85ecdac35ab091e4a Mon Sep 17 00:00:00 2001 From: David Joerg Date: Thu, 25 Apr 2013 17:49:36 -0400 Subject: [PATCH 12/16] simplify --- lib/resque/plugins/round_robin/round_robin.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index a22bfc9..2edc8ae 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -34,10 +34,8 @@ def should_work_on_queue? queuename # Ive been fighting to get this to round-robining system to work # for five hours now. If you hate this, you can fix it. # - unless ['replays', 'replays-high'].include?(queuename.to_s) || queuename.to_s.index('replay').nil? - if Resque.size("python") > 2 - return false - end + if Resque.size("python") > 2 + return false end return true if @queues.include? '*' # workers with QUEUES=* are special and are not subject to queue depth setting @@ -60,6 +58,7 @@ def should_round_robin? def reserve_with_round_robin if not should_round_robin? + print "reserving without round robin" return reserve_without_round_robin end From bb0110562e3a4dd4442b5b5da61ad83540e17e89 Mon Sep 17 00:00:00 2001 From: David Joerg Date: Fri, 26 Apr 2013 09:32:48 -0400 Subject: [PATCH 13/16] argh not so much printing plz --- lib/resque/plugins/round_robin/round_robin.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index 2edc8ae..e18c82b 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -58,7 +58,6 @@ def should_round_robin? def reserve_with_round_robin if not should_round_robin? - print "reserving without round robin" return reserve_without_round_robin end From 72a4637c7547d1858ae99f698a5cbb98842302eb Mon Sep 17 00:00:00 2001 From: David Joerg Date: Mon, 29 Apr 2013 17:16:59 -0400 Subject: [PATCH 14/16] fix it to work as my hack originally intended. hooray for staging --- lib/resque/plugins/round_robin/round_robin.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index e18c82b..cb0dd75 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -35,28 +35,24 @@ def should_work_on_queue? queuename # for five hours now. If you hate this, you can fix it. # if Resque.size("python") > 2 +# $stderr.puts "not working on queue, python queue too big. (I have #{queues.size} queues)" return false end - return true if @queues.include? '*' # workers with QUEUES=* are special and are not subject to queue depth setting - max = DEFAULT_QUEUE_DEPTH - unless ENV["RESQUE_QUEUE_DEPTH"].nil? || ENV["RESQUE_QUEUE_DEPTH"] == "" - max = ENV["RESQUE_QUEUE_DEPTH"].to_i - end - return true if max == 0 # 0 means no limiting - cur_depth = queue_depth(queuename) - log! "queue #{queuename} depth = #{cur_depth} max = #{max}" - return true if cur_depth < max - false +# $stderr.puts "working on queue, python queue is small. (I have #{queues.size} queues)" + + return true if not ['replays-low, replays-high'].include?(queuename) end # if any of our queues are wildcarded, then we want to round robin among them def should_round_robin? +# $stderr.puts "srr, @srr = #{@srr} queues=#{queues} @queues=#{@queues}" return @srr unless @srr.nil? - @srr = @queues.include? '*' + @srr = @queues[0].include? '*' end def reserve_with_round_robin + if not should_round_robin? return reserve_without_round_robin end From d073ea58231c276d7820c7b971121564469f63b6 Mon Sep 17 00:00:00 2001 From: David Joerg Date: Thu, 2 May 2013 14:56:46 -0400 Subject: [PATCH 15/16] some bugs are just so dumb you have to laugh --- lib/resque/plugins/round_robin/round_robin.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index cb0dd75..e1da331 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -39,9 +39,9 @@ def should_work_on_queue? queuename return false end -# $stderr.puts "working on queue, python queue is small. (I have #{queues.size} queues)" + # $stderr.puts "working on queue #{queuename}, python queue is small. (I have #{queues.size} queues)" - return true if not ['replays-low, replays-high'].include?(queuename) + return true if not ['replays-low', 'replays-high'].include?(queuename) end # if any of our queues are wildcarded, then we want to round robin among them From 3d5f6026dcb49e605990c2d0c3483fbd0c24c0e8 Mon Sep 17 00:00:00 2001 From: David Joerg Date: Fri, 3 May 2013 11:54:11 -0400 Subject: [PATCH 16/16] magic constant increased due to more machines --- lib/resque/plugins/round_robin/round_robin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index e1da331..cfbaa80 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -34,7 +34,7 @@ def should_work_on_queue? queuename # Ive been fighting to get this to round-robining system to work # for five hours now. If you hate this, you can fix it. # - if Resque.size("python") > 2 + if Resque.size("python") > 8 # $stderr.puts "not working on queue, python queue too big. (I have #{queues.size} queues)" return false end