SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
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...
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)
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

Más contenido relacionado

La actualidad más candente

Prevention and control of rabies
Prevention and control of rabiesPrevention and control of rabies
Prevention and control of rabies
Mohit kadyan
 
OPTION-STRATEGIES-final
OPTION-STRATEGIES-finalOPTION-STRATEGIES-final
OPTION-STRATEGIES-final
Mariam Latif
 

La actualidad más candente (18)

Eviews 9 kurulumu
Eviews 9 kurulumuEviews 9 kurulumu
Eviews 9 kurulumu
 
Concept of risk
Concept of riskConcept of risk
Concept of risk
 
Capital market
Capital marketCapital market
Capital market
 
Influenza
InfluenzaInfluenza
Influenza
 
Market efficiency and emh
Market efficiency and emhMarket efficiency and emh
Market efficiency and emh
 
Prevention and control of rabies
Prevention and control of rabiesPrevention and control of rabies
Prevention and control of rabies
 
Micro Insurance
Micro InsuranceMicro Insurance
Micro Insurance
 
Mutual funds 1
Mutual funds 1Mutual funds 1
Mutual funds 1
 
Introduction of foreign exchange market, characteristics,
Introduction of foreign exchange market, characteristics,Introduction of foreign exchange market, characteristics,
Introduction of foreign exchange market, characteristics,
 
Vogel’s Approximation Method (VAM)
Vogel’s Approximation Method (VAM)Vogel’s Approximation Method (VAM)
Vogel’s Approximation Method (VAM)
 
Insurance & risk management modeule 1 part1 a
Insurance & risk management modeule 1 part1 aInsurance & risk management modeule 1 part1 a
Insurance & risk management modeule 1 part1 a
 
Case Learning and Case Analysis
Case Learning and Case AnalysisCase Learning and Case Analysis
Case Learning and Case Analysis
 
OPTION-STRATEGIES-final
OPTION-STRATEGIES-finalOPTION-STRATEGIES-final
OPTION-STRATEGIES-final
 
MEFA IV UNIT MATERIAL
MEFA IV UNIT MATERIALMEFA IV UNIT MATERIAL
MEFA IV UNIT MATERIAL
 
Rubella (Seminar)
Rubella (Seminar)Rubella (Seminar)
Rubella (Seminar)
 
Financial Derivatives in Risk Management
Financial Derivatives in Risk ManagementFinancial Derivatives in Risk Management
Financial Derivatives in Risk Management
 
Future/Scope of Rural Insurance in India
Future/Scope of Rural Insurance in IndiaFuture/Scope of Rural Insurance in India
Future/Scope of Rural Insurance in India
 
Option cross rate
Option  cross rateOption  cross rate
Option cross rate
 

Similar a Background processing with Resque

PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
Hannes Hapke
 

Similar a Background processing with Resque (20)

A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloud
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
2019 Chef InSpec Jumpstart Part 2 of 2
2019 Chef InSpec Jumpstart Part 2 of 22019 Chef InSpec Jumpstart Part 2 of 2
2019 Chef InSpec Jumpstart Part 2 of 2
 
Celery
CeleryCelery
Celery
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
 
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
 
Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012
 
Docker 1.11 Presentation
Docker 1.11 PresentationDocker 1.11 Presentation
Docker 1.11 Presentation
 
Sheep it
Sheep itSheep it
Sheep it
 
Easy Cloud Native Transformation using HashiCorp Nomad
Easy Cloud Native Transformation using HashiCorp NomadEasy Cloud Native Transformation using HashiCorp Nomad
Easy Cloud Native Transformation using HashiCorp Nomad
 
How eBay does Automatic Outage Planning
How eBay does Automatic Outage PlanningHow eBay does Automatic Outage Planning
How eBay does Automatic Outage Planning
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
Cobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale EnvironmentsCobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale Environments
 
Cobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale EnvironmentsCobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale Environments
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

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...
  • 4.
  • 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
  • 10.
  • 11.
  • 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...