Using Queues and Concurrency to Control Performance

Suppose you are measuring the business function of order creation, specifically how long a user must wait to see confirmation that the system has their order. This timing is based on how long the CompleteOrderJob takes to complete. Imagine that Sidekiq is processing only one job at a time: each new CompleteOrderJob must wait for all existing jobs to finish before it is processed.

The following diagram shows how this might play out over a short period of time. You can see that when the first CompleteOrderJob completes, two new jobs are queued, and while the second CompleteOrderJob can be processed next, a third one that comes in must wait for the SendOrderNotificationEmailJob and RequestOrderFulfillmentJob ...

Get Ruby on Rails Background Jobs with Sidekiq now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.