Created
December 11, 2012 08:55
-
-
Save koko1000ban/4257128 to your computer and use it in GitHub Desktop.
benchmark memcached vs redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'benchmark' | |
require "securerandom" | |
namespace :dev do | |
desc "benchmark mem vs redis" | |
task :benchmark => :environment do | |
dev_server = '172.19.60.176' | |
n = 10000 | |
stores = { | |
:dalli_store => ["#{dev_server}:11211", {:namespace => 'dev', :compress => false }], | |
:redis_store => ["redis://#{dev_server}:6379/0/cache"] | |
} | |
actions = { | |
:hit => lambda{ | |
Rails.cache.fetch("test") | |
}, | |
:miss => lambda{ | |
Rails.cache.read("test_" + SecureRandom.hex(10)) | |
} | |
} | |
stores.each do |store, args| | |
ActionController::Base.cache_store = store, *args | |
Rails.cache.delete('test') | |
Rails.cache.fetch('test'){ SecureRandom.hex(30) } | |
Benchmark.bm(30) do |x| | |
actions.each do |label, proc| | |
x.report("cache_store:#{store}:#{label}") do | |
n.times do | |
proc.call | |
end | |
end | |
x.report("cache_store:#{store}:delete") do | |
n.times do |i| | |
Rails.cache.write("test_#{i}", i, :expires_in => 2) | |
end | |
n.times do |i| | |
Rails.cache.delete("test_#{i}", i) | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment