stefanwille / crystal-redis

Full featured Redis client for Crystal
MIT License
380 stars 61 forks source link

Pipeline MULTI, reduce round trips #86

Closed pgeraghty closed 4 years ago

pgeraghty commented 5 years ago

I noticed whilst using MONITOR during queuing of Sidekiq jobs (via Sidekiq.cr) that there are many round trips for MULTI and I went to look at the Ruby client, which appears to pipeline the transaction.

The code may be a bit rough (?) and probably not idiomatic to Crystal, but all tests still pass and the performance increase for me on the following benchmark w/ local Redis is ~750ms -> ~350ms.

bm = Benchmark.realtime do
  10_000.times do
    redis.multi do |api|
      ping_future = api.ping
    end
  end
end
puts bm
# ~00:00:00.350 for this branch, ~00:00:00.750 for master
stefanwille commented 5 years ago

Thanks for this! I am on vacation and will take a closer look at your PR when I am back.

pgeraghty commented 5 years ago

Thanks, Stefan. Forgot to add that I have produced some numbers for this, which you can see under my original Sidekiq.cr pull request.

stefanwille commented 4 years ago

Merged, thanks!

pgeraghty commented 4 years ago

:thumbsup: