Ruby Daemons
Upcoming SlideShare
Loading in...5
×
 

Ruby Daemons

on

  • 13 views

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.

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.

Statistics

Views

Total Views
13
Views on SlideShare
12
Embed Views
1

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 1

http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ruby Daemons Ruby Daemons Presentation Transcript

  • Ruby Daemons Creston Jamison RubyTree Software, Inc.
  • 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!
  • 1. Reliability 2. Speed
  • Background Processing Options  Delayed Job  Beanstalkd  Resque  Sidekiq  Queue Classic  Daemons
  • Delayed Job  Uses rake  Uses full rails environment  Best for long running and infrequent jobs
  • Beanstalkd  Fast queue  Does not poll  Good for raw speed  Authentication and queue management ?
  • Resque  Redis based queue system  Requires Redis  Comes with an admin interface  Uses polling
  • Sidekiq  Redis based queue system  Requires Redis  Comes with an admin interface  Uses polling  Uses threads  Code needs to be thread safe
  • Queue Classic  Postgres based queue system  Requires postgresql  Avoids separate queue process  Can avoid polling
  • Queue vs. Worker
  • Daemons  Converts a script into a daemon  Not a queue system  A way to create a worker process
  • What is a daemon?  A computer program that runs as a background process  Daemon processes typically end in ‘d’  For example: sshd
  • 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
  • Create a control file require 'rubygems' require 'bundler/setup' require 'daemons' Daemons.run('lib/daemons/event_worker.rb')
  • Loop in your script $: << File.expand_path(".", File.dirname(__FILE__)) require ‘event_processor' event_processor = EventProcessor.new loop do event_processor.process sleep(5) end
  • 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
  • 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
  • Gotchas  Need rock solid error handling  Otherwise your process dies  Need a way to skip over errors and come back to them
  • Extra Credit jstorimer.com/2012/04/19/daemon-processes-in-ruby.html labs.headlondon.com/2010/07/skinny-daemons/
  • Questions? Creston Jamison @crestonjamison creston.jamison@rubytreesoftware.com