我的应用程序有多个队列,我正在尝试确定特定队列的优先级。
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文件中的顺序排列的优先级,但也想对其进行验证。我将如何手动验证most_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设置中,产生的每个进程将遵循其自己的优先级(因此,在示例配置中,如果仅处理
bar
的进程是空闲的,而其他进程很忙,则有可能在foo
之前先处理bar
任务) 。不过,这是一个功能,而不是错误!至于如何测试它,只需将一堆作业放入每个队列中,然后观察它们是否在resque-web(或日志)中得到处理。
关于ruby-on-rails - 如何使用Resque和Redis对队列进行优先级排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64503667/