Skip to content

Instantly share code, notes, and snippets.

@bkerley
Last active December 15, 2015 00:29
Show Gist options
  • Save bkerley/5173235 to your computer and use it in GitHub Desktop.
Save bkerley/5173235 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'celluloid'
require 'riak'
require 'pp'
def p(t)
printf "%9.4f | %s\n", Time.now.to_f, t
end
p Time.now.to_s
hosts = (1..6).map do |n|
{host: 'localhost', pb_port: "808#{n}", http_port: "809#{n}"}
end
client = Riak::Client.new nodes: hosts
bucket = client.bucket 'future-get'
count = 5000
p "storing #{count} objects"
c = 0
objects = (1..count).map do |n|
o = Riak::RObject.new bucket
o.content_type = 'text/plain'
o.raw_data = "the object_id of #{n} is #{n.object_id}"
o.store
c += 1
p c if (c % 100 == 0)
end
p "done storing"
puts ""
Benchmark.bmbm do |bm|
bm.report('individual') do
individuals = objects.map(&:key).map do |k|
bucket.get k
end
end
bm.report('future complete') do
futures = objects.map(&:key).map do |k|
Celluloid::Future.new {bucket.get k}
end
sports_almanacs = futures.map(&:value)
end
end
source :rubygems
gem 'riak-client'
gem 'celluloid'
GEM
remote: http://rubygems.org/
specs:
beefcake (0.3.7)
builder (3.2.0)
celluloid (0.12.4)
facter (>= 1.6.12)
timers (>= 1.0.0)
facter (1.6.18)
i18n (0.6.4)
innertube (1.0.2)
multi_json (1.6.1)
riak-client (1.1.1)
beefcake (~> 0.3.7)
builder (>= 2.1.2)
i18n (>= 0.4.0)
innertube (~> 1.0.2)
multi_json (~> 1.0)
timers (1.1.0)
PLATFORMS
java
ruby
DEPENDENCIES
celluloid
riak-client
require 'benchmark'
require 'celluloid'
require 'riak'
require 'pp'
def p(t)
printf "%9.4f | %s\n", Time.now.to_f, t
end
p Time.now.to_s
hosts = (1..6).map do |n|
{host: 'localhost', pb_port: "808#{n}", http_port: "809#{n}"}
end
client = Riak::Client.new nodes: hosts
bucket = client.bucket 'future-get'
c = 0
bucket.get_index('$bucket', '_').each do |k|
bucket.delete k
c += 1
p c if (c % 100 == 0)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment