Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prathmeshranaut/6bed09afe8afd89a6ff7a162929dff35 to your computer and use it in GitHub Desktop.
Save prathmeshranaut/6bed09afe8afd89a6ff7a162929dff35 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)
GC.disable
ips.report("pool - 10") do
TESTS.times { pool_10.async.hashed(hash, key) }
end
GC.enable
ips.report("pool - 100") do
TESTS.times { pool_10.async.hashed(hash, key) }
end
GC.disable
ips.report("pool - 1000") do
TESTS.times { pool_10.async.hashed(hash, key) }
end
end
# Rehearsal -----------------------------------------------
# pool - 10 1.000000 0.050000 1.050000 ( 1.039771)
# pool - 100 1.390000 0.050000 1.440000 ( 1.443683)
# pool - 1000 1.140000 0.040000 1.180000 ( 1.186730)
# -------------------------------------- total: 3.670000sec
#
# user system total real
# pool - 10 1.560000 0.020000 1.580000 ( 1.575798)
# pool - 100 1.950000 0.010000 1.960000 ( 1.954645)
# pool - 1000 2.030000 0.040000 2.070000 ( 2.073388)
# E, [2016-08-10T10:18:38.516512 #5035] 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