Permalink
Browse files

update bench

  • Loading branch information...
1 parent a337065 commit f7b3936ad086fb498e82e68bace0fe1f8ebb65be @bmizerany bmizerany committed Jun 2, 2011
Showing with 57 additions and 47 deletions.
  1. +57 −47 bench/gs.rb
View
@@ -10,7 +10,7 @@
$stdout.sync = true
-abort("read <[get|set]> <total> <width> [verbose]") if (ARGV.size < 2)
+abort("gs <[get|set]> <total> <width> [verbose]") if (ARGV.size < 2)
op = ARGV.shift.to_sym
total = ARGV.shift.to_i
width = ARGV.shift.to_i
@@ -19,59 +19,69 @@
sent_at = nil
EM.run do
- client = Fraggle.connect
- sent = 0
- received = 0
- start = Time.now
+ Fraggle.connect do |c, err|
+ if err
+ raise err.message
+ end
- f = Proc.new do |r|
- received_at = Time.now
- received +=1
- latency = received_at - sent_at
+ sent = 0
+ received = 0
+ start = Time.now
- latencies << latency
- if verbose
- $stdout.puts("received=#{received} ok=#{r.ok?} rev=#{r.rev} latency=#{latency}")
- elsif (received % 10 == 0)
- $stdout.print(".")
- end
- if (received == total)
- EM.stop
- elapsed = Time.now - start
- vector = latencies.to_scale
- $stdout.puts
- $stdout.puts("total=#{total}")
- $stdout.puts("elapsed=#{elapsed}")
- $stdout.puts("rate=#{total / elapsed}")
- $stdout.puts("mean=#{vector.mean}")
- $stdout.puts("sd=#{vector.sd}")
- $stdout.puts("perc90=#{vector.percentil(90)}")
- $stdout.puts("perc99=#{vector.percentil(99)}")
- $stdout.puts("max=#{vector.max}")
- end
- end
+ f = Proc.new do |r, err|
+ if err
+ p [:err, err]
+ next
+ end
- tick = Proc.new do
- if (sent == total)
- # done sending
- elsif ((sent - received) < width)
- # pipe open
- sent_at = Time.now
- sent += 1
+ received_at = Time.now
+ received +=1
+ latency = received_at - sent_at
+
+ latencies << latency
if verbose
- $stdout.puts("sent=#{sent}")
+ $stdout.puts("received=#{received} ok=#{r.ok?} rev=#{r.rev} latency=#{latency}")
+ elsif (received % 10 == 0)
+ $stdout.print(".")
+ end
+ if (received == total)
+ EM.stop
+ elapsed = Time.now - start
+ vector = latencies.to_scale
+ $stdout.puts
+ $stdout.puts("total=#{total}")
+ $stdout.puts("elapsed=#{elapsed}")
+ $stdout.puts("rate=#{total / elapsed}")
+ $stdout.puts("mean=#{vector.mean}")
+ $stdout.puts("sd=#{vector.sd}")
+ $stdout.puts("perc90=#{vector.percentil(90)}")
+ $stdout.puts("perc99=#{vector.percentil(99)}")
+ $stdout.puts("max=#{vector.max}")
end
+ end
+
+ tick = Proc.new do
+ if (sent == total)
+ # done sending
+ elsif ((sent - received) < width)
+ # pipe open
+ sent_at = Time.now
+ sent += 1
+ if verbose
+ $stdout.puts("sent=#{sent}")
+ end
- case op
- when :get
- client.get(nil, "/processes/#{sent}", &f)
- when :set
- client.set(Fraggle::Clobber, "/processes/#{sent}", "1", &f)
+ case op
+ when :get
+ c.get(nil, "/processes/#{sent}", &f)
+ when :set
+ c.set(Fraggle::Clobber, "/processes/#{sent}", "1", &f)
+ end
+ else
+ # pipe closed
end
- else
- # pipe closed
+ EM.next_tick(&tick)
end
- EM.next_tick(&tick)
+ tick.call
end
- tick.call
end

0 comments on commit f7b3936

Please sign in to comment.