Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Asynchronous Processing for Fun and Profit

Mike Perham
November 02, 2012

Asynchronous Processing for Fun and Profit

Some pro tips and an overview of Sidekiq for great async victory!

Mike Perham

November 02, 2012
Tweet

More Decks by Mike Perham

Other Decks in Technology

Transcript

  1. How? • Client puts message on a queue • Server

    pulls message off queue • Worker executes code based on message
  2. Idempotent • Fancy computer science term • “Work can be

    applied multiple times without changing the result beyond the initial application”
  3. Idempotent • Your code has bugs! • Sidekiq will retry

    jobs that raise • Design jobs to be retried • e.g. verify you need to perform action before performing it
  4. Concurrency • Resque/DJ = 4 workers • Sidekiq = 100

    workers • Mike, what is best in life?
  5. “To crush their servers, see them smoking before you and

    hear the lamentations of their admins.”
  6. Concurrency • Use connection_pool gem to limit client connections •

    Split work into small batches • 100 items => 10 jobs of 10 items
  7. Concurrency • Thread safety rarely an issue • Most gem

    maintainers very responsive • Recently fixed: • cocaine, typheuos
  8. Threads vs Processes • Example: 400MB single-threaded process • 25

    processes = 10GB RAM = EC2 xlarge • 25 threads = 1GB RAM = EC2 small • $60/month vs $480/month • 160 dynos => 10 dynos • 150 dynos * $35/month =~ $5000/month
  9. Quick Rant • GIL + poor GC • C extension

    API must DIE • What’s larger: 50% or 800%?
  10. Server Processor Server Middleware Redis Worker Sidekiq Process Processor Server

    Middleware Worker Processor Server Middleware Worker Processor Server Middleware Worker Fetcher Manager
  11. Versions • Sidekiq - Free, LGPLv3 • Sidekiq Pro -

    more features, support, $ • motivation!
  12. Features Sidekiq Resque DJ Concurrency Store Hooks Web UI Scheduler

    Retry Delay Batches Threads Processes Processes Redis Redis DB middleware callbacks callbacks ✓ ✓ ? ✓ ? ✓ ✓ ? ✓ ✓ ? ✓ Pro ? - ? - optional
  13. Future • Nicer, more functional Web UI • APIs for

    managing queues / retries • Rails 4 Queue API