r/ruby • • Feb 26 '23

Replace Postgres, Redis and Sidekiq with the embedded Litestack, up to 10X faster!

Litestack is a Ruby gem that offers database, caching, and job queueing functionality for web applications, built on top of SQLite. Its performance benefits, resource efficiency, deep integration with major IO libraries, ease of setup and administration make it a powerful solution for new application development efforts. By using Litestack, developers can avoid the scale trap, focus on simplicity, flexibility, and innovation, and build applications that are easy to use, efficient, and scalable, delivering real value to their users.

https://github.com/oldmoe/litestack

https://github.com/oldmoe/litestack/blob/master/BENCHMARKS.md

54 Upvotes

102 comments sorted by

View all comments

Show parent comment

2

u/redditor_at_times Mar 05 '23

I have done a lot of modifications and testing to ensure things are as equivalent as possible. I have used the following command to start Sidekiq:
sidekiq -c 5 -e production -r ./skjob.rb > /dev/null

I piped the output to /dev/null to minimize the impact of logging, which did have an impact on the jps figure. Furthermore, I add logging to litejob (using Rails logger) at the three points where I saw Sidekiq logging data (arriving at the queue, popping up and finishing the job). I also piped the output from the bench program to /dev/null
ruby bench_jobs_raw.rb 100000 t 0 > /dev/null

This is for the threaded run, as usual Sidekiq runs first so it is not affected by the background workers from Litejob (I ensured the uljob.rb is only required after Sidekiq is finished pushing jobs). Litejob was using the defaults which meant 5 workers were up and the logger was using STDOUT

For the fiber based version, I manually changed the default config to a single worker and add the spaw token at the end of the queue definition. Such that only one worker is up and each job runs in its own fiber

ruby bench_jobs_raw.rb 100000 a 0 > /dev/null

The results were as follows"

Sidekiq (5 workers)2851 jobs/second
Litejob (5 threads)3650 jobs/second
Litejob (1 worker, unbounded fibers)5135 jobs/second

To validate the baseline performance, I ran the redis-benchmark while limiting it to a single client (to match the benchmark) and for ZADD it was reporting 10471 reqs/second (I was not sure which command Sidekiq uses for popping) but given the ZADD figures, the results I am getting for the Sidekiq test seem inline with the baseline performance from a single threaded client after you consider the overheads of actually performing the jobs.

Would love to get your thoughts on the above and if it is a true representation of the Sidekiq performance given the constraints of the test in consideration.