ruby-on-rails - 如何使用Resque和Redis对队列进行优先级排序

标签 ruby-on-rails ruby redis resque

我的应用程序有多个队列,我正在尝试确定特定队列的优先级。
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/

相关文章:

ruby-on-rails - 您将哪些部署目录用于 Rails 应用程序(部署到 debian 机器)?

ruby-on-rails - Link_to block 内的 Rails 简单 anchor

ruby - 当我传入数组时,为什么我的串联会困惑?

ruby-on-rails - sidekiq 在线程之间共享变量

redis - Redis Store 5MB 限制是否适用于 Express 中的 session 支持?

python - 如何在 Django 中使用 redis?

ruby-on-rails - RnR : Long running query, Heroku 超时 : webhooks? Ajax?

javascript - 提交按钮不提交表单,但检查验证

ruby - 如何在 mailto 链接中找到正文和主题?

phpredis : RedisException [ 0 ]: protocol error, 得到 't' 作为回复类型字节