Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Created July 17, 2013 16:42
Show Gist options
  • Select an option

  • Save sorentwo/6022293 to your computer and use it in GitHub Desktop.

Select an option

Save sorentwo/6022293 to your computer and use it in GitHub Desktop.
Dalli pipelining performance comparison
# Two separate multi blocks are used, the first leveraging `get_multi`
Calculating -------------------------------------
fetch 19 i/100ms
fetch_multi 78 i/100ms
-------------------------------------------------
fetch 192.2 (±2.1%) i/s - 969 in 5.044695s
fetch_multi 759.7 (±2.5%) i/s - 3822 in 5.034430s
require 'dalli'
require 'active_support/json'
require 'active_support/cache'
require 'active_support/cache/dalli_store'
require 'benchmark/ips'
client = ActiveSupport::Cache::DalliStore.new('localhost', namespace: 'pipelining-bm')
objects = 30.times.inject({}) do |hash, i|
hash[i.to_s] = { id: i, value: 'abcdefg' }
hash
end
GC.disable
Benchmark.ips do |x|
x.report('fetch') do
objects.each do |key, object|
client.fetch(key) { object[:value] }
end
client.clear
end
x.report('fetch_multi') do
client.fetch_multi(*objects.keys) do |key|
objects[key][:value]
end
client.clear
end
end
# All read/write operations wrapped inside of a single multi block
Calculating -------------------------------------
fetch 19 i/100ms
fetch_multi 33 i/100ms
-------------------------------------------------
fetch 195.8 (±1.0%) i/s - 988 in 5.045953s
fetch_multi 335.3 (±0.9%) i/s - 1683 in 5.020209s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment