Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prathmeshranaut/c911cba8a03626307ce3bdaef832d48b to your computer and use it in GitHub Desktop.
Save prathmeshranaut/c911cba8a03626307ce3bdaef832d48b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "celluloid/autostart"
require "benchmark"
class Worker
include Celluloid
def hashed(hash, key)
hash[key]
end
end
pool_10 = Worker.pool(size: 10)
pool_100 = Worker.pool(size: 100)
pool_1000 = Worker.pool(size: 1000)
hash = {}
ENTRIES = 10_000
ENTRIES.times do |i|
hash[i] = i
end
TESTS = 400_000
Benchmark.bmbm do |ips|
key = rand(10_000)
ips.report("pool - 10") do
TESTS.times { pool_10.async.hashed(hash, key) }
end
ips.report("pool - 100") do
TESTS.times { pool_10.async.hashed(hash, key) }
end
ips.report("pool - 1000") do
TESTS.times { pool_10.async.hashed(hash, key) }
end
end
# Rehearsal -----------------------------------------------
# pool - 10 2.020000 0.040000 2.060000 ( 2.057549)
# pool - 100 2.680000 0.040000 2.720000 ( 2.725230)
# pool - 1000 2.140000 0.040000 2.180000 ( 2.181185)
# -------------------------------------- total: 6.960000sec
#
# user system total real
# pool - 10 1.930000 0.030000 1.960000 ( 1.969274)
# pool - 100 1.990000 0.030000 2.020000 ( 2.014895)
# pool - 1000 2.720000 0.030000 2.750000 ( 2.752594)
# E, [2016-08-09T19:45:19.450121 #3530] ERROR -- : Couldn't cleanly terminate all actors in 10 seconds!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment