简体   繁体   English

如何使用线程在Puma或Raptor服务器上运行Sidekiq作业?

[英]How can I dedicate threads to run Sidekiq jobs with Puma or Raptor server?

Let's say my process will run 3 workers, and I want to dedicate 1 of them to process web requests, and 2 to handle Sidekiq background jobs, each process potentially being multi-threaded. 假设我的进程将运行3个工作进程,我想其中的1个专门处理Web请求,2个专门处理Sidekiq后台作业,每个进程都有可能是多线程的。 Is there an easy or best-practices way to handle this? 有没有简单或最佳实践的方式来处理此问题? I've tried a few different configurations, but they either give me an error, or just don't process the jobs at all. 我尝试了几种不同的配置,但是它们给我一个错误,或者根本不处理作业。

I'm using Rails 4 and ActiveJob, but I don't think those points are relevant. 我正在使用Rails 4和ActiveJob,但我认为这些要点无关紧要。

You don't have to take care of sidekiq worker scheduling from you rails application. 您无需从Rails应用程序中进行sidekiq worker调度。 Sidekiq runs a separate process with the whole rails environment for managing the background workers. Sidekiq在整个Rails环境中运行一个单独的过程,用于管理后台工人。 Each Worker is a separate Thread, backed by the Celluloid Actor framework. 每个Worker是一个独立的线程,并由Celluloid Actor框架支持。 So for your setup you just do the following: 因此,对于您的设置,您只需执行以下操作:

# start a single puma web server process with min 4 and max 16 Threads
$ bundle exec puma -t 4:16  

# start a single multithreaded sidekiq process,    
# with councurrency settings defined in sidekiq.yml
$ bundle exec sidekiq --pidfile tmp/pids/sidekiq_1.pid 

# start another sidekiq process (if really necessary)
$ bundle exec sidekiq --pidfile tmp/pids/sidekiq_2.pid  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM