如何使用 Resque 和 Redis 确定队列的优先级
How to prioritize queues using Resque and Redis
我的应用程序有多个队列,我正在尝试确定特定队列的优先级。
resque-pool.yml
development:
"high_priority, med_priority, low_priority": 1
根据 resque-pool 文档 (https://github.com/nevans/resque-pool) 示例:
resque-pool.yml
foo: 1
bar: 2
"foo,bar,baz": 1
production:
"foo,bar,baz": 4
"这将启动七个工作进程,一个专用于 foo 队列,两个专用于 bar 队列,四个工作进程优先查看所有队列。使用上面的配置,这类似于如果你 运行 以下内容:"
rake resque:work RAILS_ENV=production QUEUES=foo &
rake resque:work RAILS_ENV=production QUEUES=bar &
rake resque:work RAILS_ENV=production QUEUES=bar &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
我认为队列按它们在 yaml 文件中的顺序排列优先级,但也想验证它。
我如何手动验证 highest_priority 队列中的作业优先于 med_priority 和 low_priority 队列中的作业?我是否遗漏了某些东西以便正确确定它们的优先级?
你说得对。正如主要 Resque documentation 所述:
Resque doesn't support numeric priorities but instead uses the order of queues you give it. We call this list of queues the "queue list."
Let's say we add a warm_cache queue in addition to our file_serve queue. We'd now start a worker like so:
$ QUEUES=file_serve,warm_cache rake resque:work
When the worker looks for new jobs, it will first check file_serve. If it finds a job, it'll process it then check file_serve again. It will keep checking file_serve until no more jobs are available. At that point, it will check warm_cache. If it finds a job it'll process it then check file_serve (repeating the whole process).
In this way you can prioritize certain queues.
请注意,在 resque-pool 设置中,每个生成的进程都将遵循自己的优先级(因此在示例配置中,可能会在 foo
个作业之前处理 bar
个作业如果仅处理 bar
的进程空闲而其他进程忙)。不过,这是一项功能,不是错误!
至于如何测试它,只需在每个队列中加入一堆作业,然后在 resque-web(或日志)中观察它们的处理情况。
我的应用程序有多个队列,我正在尝试确定特定队列的优先级。
resque-pool.yml
development:
"high_priority, med_priority, low_priority": 1
根据 resque-pool 文档 (https://github.com/nevans/resque-pool) 示例:
resque-pool.yml
foo: 1
bar: 2
"foo,bar,baz": 1
production:
"foo,bar,baz": 4
"这将启动七个工作进程,一个专用于 foo 队列,两个专用于 bar 队列,四个工作进程优先查看所有队列。使用上面的配置,这类似于如果你 运行 以下内容:"
rake resque:work RAILS_ENV=production QUEUES=foo &
rake resque:work RAILS_ENV=production QUEUES=bar &
rake resque:work RAILS_ENV=production QUEUES=bar &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
rake resque:work RAILS_ENV=production QUEUES=foo,bar,baz &
我认为队列按它们在 yaml 文件中的顺序排列优先级,但也想验证它。
我如何手动验证 highest_priority 队列中的作业优先于 med_priority 和 low_priority 队列中的作业?我是否遗漏了某些东西以便正确确定它们的优先级?
你说得对。正如主要 Resque documentation 所述:
Resque doesn't support numeric priorities but instead uses the order of queues you give it. We call this list of queues the "queue list."
Let's say we add a warm_cache queue in addition to our file_serve queue. We'd now start a worker like so:
$ QUEUES=file_serve,warm_cache rake resque:work
When the worker looks for new jobs, it will first check file_serve. If it finds a job, it'll process it then check file_serve again. It will keep checking file_serve until no more jobs are available. At that point, it will check warm_cache. If it finds a job it'll process it then check file_serve (repeating the whole process).
In this way you can prioritize certain queues.
请注意,在 resque-pool 设置中,每个生成的进程都将遵循自己的优先级(因此在示例配置中,可能会在 foo
个作业之前处理 bar
个作业如果仅处理 bar
的进程空闲而其他进程忙)。不过,这是一项功能,不是错误!
至于如何测试它,只需在每个队列中加入一堆作业,然后在 resque-web(或日志)中观察它们的处理情况。