Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ruby Daemons


Published on

Learn how to use daemons with your ruby based application like Ruby on Rails. See how it compares to other queueing systems like Queue Classic, Sidekiq, or Delayed Job.

Published in: Software
  • @Alexander Stamp Well, a daemon is good when you want to do something or respond to something continually and immediately. You want to dedicate ongoing resources to be ready at a moments notice. For example a running web server is essentially a daemon process. It uses dedicated resources and is ready to go at a moments notice. A job queue on the other hand is for things that need spin up or ramp up time. For example, when you don't want a worker running all the time and using resources, use a job queue. Startup the worker when a new job comes into the queue, do the work and then stop.
    Are you sure you want to  Yes  No
    Your message goes here
  • Hey, this is a great slideshow but can you detail more about the trade-offs between daemons and like sidekiq? I got a good sense of the pros and cons of delayed job vs sidekiq vs others but not much comparison between daemons and other options.
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Ruby Daemons

  1. 1. Ruby Daemons Creston Jamison RubyTree Software, Inc.
  2. 2. GAMEhud  HTTPAPI accepts event and player based data from game clients.  Incoming data needs to be distributed between 10-20 tables.  Don’t want to do that in the request.  Need to do background processing!
  3. 3. 1. Reliability 2. Speed
  4. 4. Background Processing Options  Delayed Job  Beanstalkd  Resque  Sidekiq  Queue Classic  Daemons
  5. 5. Delayed Job  Uses rake  Uses full rails environment  Best for long running and infrequent jobs
  6. 6. Beanstalkd  Fast queue  Does not poll  Good for raw speed  Authentication and queue management ?
  7. 7. Resque  Redis based queue system  Requires Redis  Comes with an admin interface  Uses polling
  8. 8. Sidekiq  Redis based queue system  Requires Redis  Comes with an admin interface  Uses polling  Uses threads  Code needs to be thread safe
  9. 9. Queue Classic  Postgres based queue system  Requires postgresql  Avoids separate queue process  Can avoid polling
  10. 10. Queue vs. Worker
  11. 11. Daemons  Converts a script into a daemon  Not a queue system  A way to create a worker process
  12. 12. What is a daemon?  A computer program that runs as a background process  Daemon processes typically end in ‘d’  For example: sshd
  13. 13. Setting up a daemon  Install daemons gem  Create a control file event_worker_control.rb  Create a loop in the script called by the control file event_worker.rb
  14. 14. Create a control file require 'rubygems' require 'bundler/setup' require 'daemons''lib/daemons/event_worker.rb')
  15. 15. Loop in your script $: << File.expand_path(".", File.dirname(__FILE__)) require ‘event_processor' event_processor = loop do event_processor.process sleep(5) end
  16. 16. Control your daemon  ruby daemon-name_control.rb start  ruby daemon-name_control.rb restart  ruby daemon-name_control.rb stop  ruby lib/daemons/event_worker_control.rb start -- production  PID file
  17. 17. Capistrano before 'deploy:update_code', 'deploy:stop_workers' desc "Stop the worker processes“ task :stop_workers, :roles => :app do run "cd #{current_path}; ruby lib/daemons/event_worker_control.rb stop -- production“ end
  18. 18. Gotchas  Need rock solid error handling  Otherwise your process dies  Need a way to skip over errors and come back to them
  19. 19. Extra Credit
  20. 20. Questions? Creston Jamison @crestonjamison