Skip to content

Instantly share code, notes, and snippets.

@chochkov
Created September 20, 2011 11:38
Show Gist options
  • Save chochkov/1228905 to your computer and use it in GitHub Desktop.
Save chochkov/1228905 to your computer and use it in GitHub Desktop.
Redis/Resque benchmark
require File.join(File.dirname(__FILE__), '..', 'lib', 'crumbs', 'collection', 'job')
require 'benchmark'
module Crumbs
class Gretel
class << self
def call(env)
if crumb = get_crumb(Rack::Request.new(env))
a = Benchmark.measure {
Resque.enqueue(CollectJob, crumb) # 0.01588
}
b = Benchmark.measure {
Redis.new.sadd('crumbs', crumb) # 0.01095
}
$redis = Redis.new
c = Benchmark.measure {
$redis.sadd('crumbs', 'ccccc') # 0.00039
}
Logger.new($stdout).debug "#{a.real}\n\n #{b.real}\n\n #{c.real}"
end
[ 200, {}, [] ]
end
def get_crumb(request)
if request.host == URI.parse(request.referrer).host
request.POST["json"]
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment