1 / 16

Background Processing In Ruby

Background Processing In Ruby. Khash Sajadi @ khash. Do I need them?. HTTP downloads Image Resizing Search Index Updates Batch Jobs Spam Checks Uploads Provisioning of a Box Sending Emails Throttling Calls Housekeeping Jobs. What’s on the menu?. Delayed Job / Navvy

tessa
Download Presentation

Background Processing In Ruby

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Background Processing In Ruby Khash Sajadi @khash

  2. Do I need them? • HTTP downloads • Image Resizing • Search Index Updates • Batch Jobs • Spam Checks • Uploads • Provisioning of a Box • Sending Emails • Throttling Calls • Housekeeping Jobs

  3. What’s on the menu? • Delayed Job / Navvy • Resque / Sidekiq • DIY (EventMachine, CRON, Spawn…) • Hosted Solutions (IronWorker)

  4. Delayed Job / Navvy • ActiveRecord based (Delayed Job) • DB agnostic (Navvy) • Ruby object with Perform method

  5. Delayed Job / Navvy classMyJob < Struct.new(:text, :emails) defperform emails.each { |e| MyMailer.deliver_text_to_email(text, e) } end end Delayed::Job.enqueueMyJob.new( 'loremipsum...', Users.all.collect(&:email) ) rake jobs:work

  6. Resque • Redis backed • Very similar usage to Delayed Job

  7. Resque classArchive @queue = :file_serve defself.perform(repo_id, branch = 'master') repo = Repository.find(repo_id) repo.create_archive(branch) end end Resque.enqueue(Archive, self.id, branch) rake resque:work QUEUE=*

  8. Resque • Resque Scheduler • ResqueWeb

  9. Testing • resque_unit • Delayed Job kill switch

  10. Forking Threads • Resque vs. Sidekiq • MRI < 1.9 and MRI > 1.9 • REE and JRuby

  11. Keep it up • God, Bluepill, upstart • Procfile • Foreman worker: rake rescue:work QUEUE=* scheduler: rake resque:scheduler

  12. Let’s grow • Vertical Scaling (more workers) • Horizontal Scaling (more boxes) • Error / Dead Letter Queues • Auto Scale

  13. Gotcha! • Always use IDs • Beware of serialization • Don’t hog workers • Be stateless / idempotent • Breakup jobs to atomic parts • Beware of concurrency • Logging and exception handling

  14. Beyond Jobs • Use a solid middleware ( RabbitMQ, ActiveMQ, SQS,…) • Transactions • Distributed transactions

  15. Further Reading • Background Jobs in Ruby on Rails http://4loc.wordpress.com/2010/03/10/background-jobs-in-ruby-on-rails/ • Sidekiq vs. Resquehttp://joshrendek.com/2012/11/sidekiq-vs-resque/

  16. Thank you! Khash Sajadi @khash Download the slides at: bit.ly/T9oJNN

More Related