SlideShare a Scribd company logo
Resque
Background processing
System administration on a multi-
        instances setup

      Experience feedback

            Plugins

          Nicolas Blanco
             Novapost
My project : bookandgolf.com
bookandgolf.com
At launch :

  • more than 60 golfs to synchronise
  • 4 different APIs
  • More than 350 000 slots (starts) to synchronize every 2 hours

At first we tried to do the synchronization with cron tasks... but...
Background processing with Resque
nginx          resque-web
:web



             redis-server
:db

       worker 1




                        Current
       worker 2


:app
       worker 3
                        architecture

       worker 4
Resque job class

class MyKikoololSleepJob
  @queue = :medium

  def self.perform(sleep_duration)
    sleep sleep_duration
  end
end



Resque.enqueue(MyKikoololSleepJob, 10)
Resque workers

rake environment resque:work QUEUE=medium


rails@www:~$ ps aux | grep resque

rails  8950  sh -c cd /home/rails/www/socianalytics/current &&
rake environment resque:work QUEUE=high,medium,low
...
rails  8951  resque-1.9.10: Forked 9105 at 1302095560               
rails  9105  resque-1.9.10: Processing medium since 1302095560      
Resque workers Unix signals


• QUIT - Wait for child to finish processing then exit

• TERM / INT - Immediately kill child then exit

• USR1 - Immediately kill child but don't exit

• USR2 - Don't start to process any new jobs

• CONT - Start to process new jobs again after a USR2
Resque-web (Sinatra webapp)
Background processing with Resque
Background processing with Resque
God setup - my way!
Versioned god config files by instance name, ie :

•   god / app.god
•   god / web.god
•   god / db.god
•   ...

God init.d file found on gist.github.com :)

god.conf :
GOD_CONFIG=/home/rails/www/bookgolf/current/god/db.god
GOD_COMMAND="sudo -u rails /usr/local/bin/god"
GOD_LOG=/home/rails/log/god.log
God config

# Resque
God.watch do |w|
  w.env = { 'RAILS_ROOT' => rails_root,
              'RAILS_ENV'  => rails_env }

  w.name          = "resque-worker"
  w.interval      = 30.seconds
  w.start         = "cd #{rails_root} && rake
environment resque:work QUEUE=high,medium,low"
  w.start_grace   = 10.seconds
  
  ...
Workers graceful restart
Rake task to restart workers, the "graceful"
way

namespace :resque do
  task :restart_workers => :environment do
    pids = Array.new
    
    Resque.workers.each do |worker|
      pids << worker.to_s.split(/:/).second if
worker.to_s.include?(Settings.resque.localhost_name)
    end
    
    if pids.size > 0
      system("kill -QUIT #{pids.join(' ')}")
    end
    
    system("rm /home/rails/.god/pids/resque-worker*.pid")
  end
end
Workers graceful restart

namespace :resque do
  task :restart_workers, :roles => [:app, :db] do
    rake "resque:restart_workers"
  end
end
Resque-web - Final setup

• Launched externally with nginx reverse proxy (easy to add
  http basic auth)


• External Ruby config file to change Redis setup, load
  plugins, etc.

     resque-web config/resque-web.rb
Resque-web God monitoring
%w{5678}.each do |port|
  God.watch do |w|

    w.env = { 'RAILS_ROOT' => rails_root,
              'RAILS_ENV'  => rails_env }

    w.uid       =   "rails"
    w.name      =   "resque-web"
    w.interval  =   30.seconds
    w.start     =   "cd #{rails_root} && resque-web config/resque-
web.rb"

    w.start_grace   = 15.seconds

    w.start_if do |start|
      start.condition(:process_running) do |c|
          c.interval = 5.seconds
          c.running = false
      end
    end
  end
end
ActiveRecord - timeout / stale :(

Fast workaround...

   ...

   ActiveRecord::Base.connection.reconnect!

   ...
Resque plugins

• defunkt / resque-lock


Prevent two workers from working on the same
Job class with same arguments
Resque plugins

• jayniz / resque-loner

TIP :

Do not forget to :
  require "resque-loner"
in your Resque-web config.rb file! or... FAIL (cleared jobs won't
be relaunched again!)

BAD :

Need inheritance in job classes :'(... But a fork exists that
doesn't need it.
Other plugins...

Look @ github.com/defunkt/resque
Wiki!


And remember that with a good
system architecture, Resque is just...
Background processing with Resque

More Related Content

KEY
Background Jobs with Resque
KEY
Php resque
KEY
GPerf Using Jesque
PPTX
Capistrano - automate all the things
PPT
Open Source Saturday - How can I contribute to Ruby on Rails?
PPTX
Getting Started with Capistrano
PPT
Capistrano
PDF
Scaling up task processing with Celery
Background Jobs with Resque
Php resque
GPerf Using Jesque
Capistrano - automate all the things
Open Source Saturday - How can I contribute to Ruby on Rails?
Getting Started with Capistrano
Capistrano
Scaling up task processing with Celery

What's hot (20)

PDF
Infrastructure = code - 1 year later
PDF
A quick intro to Ansible
PDF
Matthew Eernisse, NodeJs, .toster {webdev}
PDF
Celery for internal API in SOA infrastructure
PDF
Building Distributed System with Celery on Docker Swarm
PDF
Introduction to Celery
PDF
Designing net-aws-glacier
PDF
Ansible 2 and Ansible Galaxy 2
PDF
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
PDF
Trying Continuous Delivery - pyconjp 2012
PDF
kRouter
PPTX
Toolbox of a Ruby Team
PPTX
Controlling multiple VMs with the power of Python
PDF
Introduction to Ansible (Pycon7 2016)
PDF
Testing your infrastructure with litmus
KEY
Node.js
PDF
Autoscaling with hashi_corp_nomad
PDF
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
ODP
Chef training Day5
PDF
Take control of your Jenkins jobs via job DSL.
Infrastructure = code - 1 year later
A quick intro to Ansible
Matthew Eernisse, NodeJs, .toster {webdev}
Celery for internal API in SOA infrastructure
Building Distributed System with Celery on Docker Swarm
Introduction to Celery
Designing net-aws-glacier
Ansible 2 and Ansible Galaxy 2
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Trying Continuous Delivery - pyconjp 2012
kRouter
Toolbox of a Ruby Team
Controlling multiple VMs with the power of Python
Introduction to Ansible (Pycon7 2016)
Testing your infrastructure with litmus
Node.js
Autoscaling with hashi_corp_nomad
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
Chef training Day5
Take control of your Jenkins jobs via job DSL.
Ad

Similar to Background processing with Resque (20)

KEY
Asynchronous Awesome
PDF
Porting Rails Apps to High Availability Systems
KEY
TorqueBox - Ruby Hoedown 2011
PDF
Introduction to Resque
KEY
Lessons from Branch's launch
ODP
Deferred Processing in Ruby - Philly rb - August 2011
ZIP
Message Queues in Ruby - An Overview
PDF
Work Queue Systems
KEY
Foreman - Process manager for applications with multiple components
PPTX
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
KEY
Ruby on the server
KEY
Cooking a rabbit pie
PDF
Torquebox OSCON Java 2011
PDF
Migrating from Backgroundrb to Resque
PDF
Gearman: A Job Server made for Scale
PDF
TorqueBox for Rubyists
PDF
Distributed Queue System using Gearman
PDF
Resque
KEY
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
PDF
Working with Asynchronous Events
Asynchronous Awesome
Porting Rails Apps to High Availability Systems
TorqueBox - Ruby Hoedown 2011
Introduction to Resque
Lessons from Branch's launch
Deferred Processing in Ruby - Philly rb - August 2011
Message Queues in Ruby - An Overview
Work Queue Systems
Foreman - Process manager for applications with multiple components
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
Ruby on the server
Cooking a rabbit pie
Torquebox OSCON Java 2011
Migrating from Backgroundrb to Resque
Gearman: A Job Server made for Scale
TorqueBox for Rubyists
Distributed Queue System using Gearman
Resque
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
Working with Asynchronous Events
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Cloud computing and distributed systems.
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
A Presentation on Artificial Intelligence
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Cloud computing and distributed systems.
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Chapter 3 Spatial Domain Image Processing.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
A Presentation on Artificial Intelligence
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Understanding_Digital_Forensics_Presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Monthly Chronicles - July 2025
20250228 LYD VKU AI Blended-Learning.pptx

Background processing with Resque

  • 1. Resque Background processing System administration on a multi- instances setup Experience feedback Plugins Nicolas Blanco Novapost
  • 2. My project : bookandgolf.com
  • 3. bookandgolf.com At launch : • more than 60 golfs to synchronise • 4 different APIs • More than 350 000 slots (starts) to synchronize every 2 hours At first we tried to do the synchronization with cron tasks... but...
  • 5. nginx resque-web :web redis-server :db worker 1 Current worker 2 :app worker 3 architecture worker 4
  • 6. Resque job class class MyKikoololSleepJob   @queue = :medium   def self.perform(sleep_duration)     sleep sleep_duration   end end Resque.enqueue(MyKikoololSleepJob, 10)
  • 7. Resque workers rake environment resque:work QUEUE=medium rails@www:~$ ps aux | grep resque rails  8950  sh -c cd /home/rails/www/socianalytics/current && rake environment resque:work QUEUE=high,medium,low ... rails  8951  resque-1.9.10: Forked 9105 at 1302095560                rails  9105  resque-1.9.10: Processing medium since 1302095560      
  • 8. Resque workers Unix signals • QUIT - Wait for child to finish processing then exit • TERM / INT - Immediately kill child then exit • USR1 - Immediately kill child but don't exit • USR2 - Don't start to process any new jobs • CONT - Start to process new jobs again after a USR2
  • 12. God setup - my way! Versioned god config files by instance name, ie : • god / app.god • god / web.god • god / db.god • ... God init.d file found on gist.github.com :) god.conf : GOD_CONFIG=/home/rails/www/bookgolf/current/god/db.god GOD_COMMAND="sudo -u rails /usr/local/bin/god" GOD_LOG=/home/rails/log/god.log
  • 13. God config # Resque God.watch do |w|   w.env = { 'RAILS_ROOT' => rails_root,               'RAILS_ENV'  => rails_env }   w.name          = "resque-worker"   w.interval      = 30.seconds   w.start         = "cd #{rails_root} && rake environment resque:work QUEUE=high,medium,low"   w.start_grace   = 10.seconds      ...
  • 14. Workers graceful restart Rake task to restart workers, the "graceful" way namespace :resque do   task :restart_workers => :environment do     pids = Array.new          Resque.workers.each do |worker|       pids << worker.to_s.split(/:/).second if worker.to_s.include?(Settings.resque.localhost_name)     end          if pids.size > 0       system("kill -QUIT #{pids.join(' ')}")     end          system("rm /home/rails/.god/pids/resque-worker*.pid")   end end
  • 15. Workers graceful restart namespace :resque do   task :restart_workers, :roles => [:app, :db] do     rake "resque:restart_workers"   end end
  • 16. Resque-web - Final setup • Launched externally with nginx reverse proxy (easy to add http basic auth) • External Ruby config file to change Redis setup, load plugins, etc.      resque-web config/resque-web.rb
  • 17. Resque-web God monitoring %w{5678}.each do |port|   God.watch do |w|     w.env = { 'RAILS_ROOT' => rails_root,               'RAILS_ENV'  => rails_env }     w.uid       = "rails"     w.name      = "resque-web"     w.interval  = 30.seconds     w.start     = "cd #{rails_root} && resque-web config/resque- web.rb"     w.start_grace   = 15.seconds     w.start_if do |start|       start.condition(:process_running) do |c|           c.interval = 5.seconds           c.running = false       end     end   end end
  • 18. ActiveRecord - timeout / stale :( Fast workaround...    ...    ActiveRecord::Base.connection.reconnect!    ...
  • 19. Resque plugins • defunkt / resque-lock Prevent two workers from working on the same Job class with same arguments
  • 20. Resque plugins • jayniz / resque-loner TIP : Do not forget to :   require "resque-loner" in your Resque-web config.rb file! or... FAIL (cleared jobs won't be relaunched again!) BAD : Need inheritance in job classes :'(... But a fork exists that doesn't need it.
  • 21. Other plugins... Look @ github.com/defunkt/resque Wiki! And remember that with a good system architecture, Resque is just...