Mike
Mike

Reputation: 333

Does ActiveJob with Sidekiq adapter have performance issue against pure Sidekiq worker?

I see this in Sidekiq official wiki that ActiveJob would be much slower.

But it is mentioned on Mar 2018, based on Rails 4.2 and Sidekiq 5.1.1 according to this issue, and the latest would be Rails 6 and Sidekiq 6.

Is it still this case that pure Sidekiq worker would be much suggested than ActiveJob with Sidekiq adapter?

Upvotes: 2

Views: 1482

Answers (2)

Mike
Mike

Reputation: 333

I prepared a simple benchmark: https://github.com/mpan-wework/sidekiq-benchmark/actions?query=workflow%3ARSpec

CreateUserJob
  behaves like Benchmark Job
"CreateUserJob-0, 1601366451612"
"CreateUserJob-last, 500, 1601366532766"
    runs for 501 times

PureJob
  behaves like Benchmark Job
"PureJob-0, 1601366532791"
"PureJob-last, 500, 1601366542691"
    runs for 501 times

CreateUserWorker
  behaves like Benchmark Worker
"CreateUserWorker-0, 1601366542695"
"CreateUserWorker-last, 500, 1601366621057"
    runs for 501 times

PureWorker
  behaves like Benchmark Worker
"PureWorker-0, 1601366621072"
"PureWorker-last, 500, 1601366630103"
    runs for 501 times

Finished in 2 minutes 58.5 seconds (files took 1.72 seconds to load)
4 examples, 0 failures

The benchmark result is run over github actions with one postgres container as database and one redis container as cache.

Pure job or worker only contains in-memory commands, CreateUser job or worker will create 100 users through SQL.

0 represents the timestamp of the first job/worker to run; when every job/worker finishes, it will write its id and end time to cache, so last represents the last job/worker.

For each type of job/worker, 501 items are enqueued.

From the data collected, PureJob takes 9.900 seconds while PureWorker takes 9.031 seconds; CreateUserJob takes 81.154 seconds while CreateUserWorker takes 78.362 seconds. Sidekiq worker is faster than ActiveJob with Sidekiq adapter, but not as much as stated.

I have not yet tested on kubernetes cluster with multiple rails and sidekiq pods, but I guess the difference would not be significant.

Upvotes: 2

Mike Perham
Mike Perham

Reputation: 22208

ActiveJob is an adapter layer on top of Sidekiq::Worker, it will always add overhead. That said, how much overhead is version-, application- and usecase-specific so only you can measure your own system to determine the kind of overhead you are seeing.

Benchmarks show that Active Job is 2-20x times slower pushing jobs to Redis and has ~3x the processing overhead (with Rails 5.1.4 and Sidekiq 5.1.1).

https://github.com/mperham/sidekiq/wiki/Active-Job#performance

Upvotes: 0

Related Questions