Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add session benchmarks.

Workaround for rufus exceptions in the while.
  • Loading branch information...
commit 3d6e4d88f77e872826bec3d76d1eca2974248863 1 parent 4d38538
@nofxx authored
View
9 benchmark/cache.rb
@@ -18,7 +18,7 @@
class User; attr_accessor :name, :info; end
u = User.new; u.name = P; u.info = G
O = u
-T = 10_000
+T = ARGV[0].to_i || 10000
#TODO: Cabinet & memcached C bindings
TEST = {
@@ -61,14 +61,15 @@ class User; attr_accessor :name, :info; end
thr = []
Benchmark.bmbm do |b|
TEST.each_pair do |k,s|
- b.report("#{k} TW") { 100.times { |j| thr << Thread.new { 100.times { |i| s.write "#{j}-#{i}", X }}}; thr.each { |t| t.join }; thr = [] }
- b.report("#{k} TR") { 100.times { |j| thr << Thread.new { 100.times { |i| s.read "#{j}-#{i}" }}}; thr.each { |t| t.join }; thr = [] }
+ b.report("#{k} TW") { (T/2).times { |j| thr << Thread.new { (T/2).times { |i| s.write "#{j}-#{i}", X }}}; thr.each { |t| t.join }; thr = [] }
+ b.report("#{k} TR") { (T/2).times { |j| thr << Thread.new { (T/2).times { |i| s.read "#{j}-#{i}" }}}; thr.each { |t| t.join }; thr = [] }
end
end
__END__
-
+*NOTE: Redis and Memcache support native expiration, Tokyo doesn't.
+Wondering the impact of this feature written in ruby...
Core 2 Duo 8500 - 3.16Ghz
------------------------------------------------------------
View
70 benchmark/session.rb
@@ -0,0 +1,70 @@
+#
+# Tokyo Store
+#
+# Session Benchmark vs MemCacheStore on memcached and tyrant
+#
+$: << File.join(File.dirname(__FILE__), "/../lib")
+require 'rubygems'
+require 'benchmark'
+require 'rack'
+require 'tokyo_store'
+require 'redis-store'
+#S = [Rack::Session::Tokyo::DEFAULT_OPTIONS[:key], { :test => "foo"}]
+T = ARGV[0].to_i || 10000
+
+rack = lambda do |env|
+ env["rack.session"]["counter"] ||= 0
+ env["rack.session"]["counter"] += 1
+ Rack::Response.new(env["rack.session"].inspect).to_a
+end
+
+TEST = {
+ "Tokyo" => Rack::Session::Tokyo.new(rack),
+ "Redis" => Rack::Session::Redis.new(rack),
+}
+bar = "_" * 45
+
+puts "\n#{bar} GET"
+Benchmark.bmbm do |b|
+ TEST.each_pair do |n,s|
+ b.report(n) do T.times do
+ req = Rack::MockRequest.new(s)
+ cookie = req.get("/")["Set-Cookie"]
+ req.get("/", "HTTP_COOKIE" => cookie)
+ end end
+ end
+end
+
+puts "\n#{bar} SET"
+Benchmark.bmbm do |b|
+ TEST.each_pair do |n,s|
+ b.report(n) { T.times { Rack::MockRequest.new(s).get("/") }}
+ end
+end
+
+puts "\n#{bar} EXIST"
+Benchmark.bmbm do |b|
+ TEST.each_pair do |n,s|
+ b.report(n) do T.times do
+ Rack::MockRequest.new(s).get("/", "HTTP_COOKIE" => "rack.session=badbadcookie")
+ end end
+ end
+end
+
+
+__END__
+
+_____________________________________________ GET
+Tokyo 6.310000 1.030000 7.340000 ( 8.511138)
+Redis 7.300000 1.010000 8.310000 ( 9.325441)
+------------------------------- total: 15.650000sec
+
+_____________________________________________ SET
+Tokyo 3.340000 0.540000 3.880000 ( 4.562920)
+Redis 3.960000 0.540000 4.500000 ( 5.030627)
+-------------------------------- total: 8.380000sec
+
+_____________________________________________ EXIST
+Redis 4.700000 0.700000 5.400000 ( 6.061131)
+Tokyo 4.090000 0.650000 4.740000 ( 5.537898)
+------------------------------- total: 10.140000sec
View
4 lib/rack/session/tokyo.rb
@@ -48,9 +48,13 @@ def set_session(env, sid, new_session, options)
@pool[sid] = options && options[:raw] ? session : Marshal.dump(session)
return sid
rescue => e
+ if e =~ /refused/
warn "#{self} is unable to find server, error: #{e}"
warn $!.inspect
return false
+ else
+ raise e
+ end
ensure
@mutex.unlock if env['rack.multithread']
end
Please sign in to comment.
Something went wrong with that request. Please try again.