Skip to content

Instantly share code, notes, and snippets.

@bkerley
Created January 8, 2014 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkerley/8311490 to your computer and use it in GitHub Desktop.
Save bkerley/8311490 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'beefcake'
require 'yaml'
require 'pry'
require 'pp'
puts "Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
puts Time.now.to_s
puts Process.pid
class RpbPair
include Beefcake::Message
required :key, :bytes, 1
optional :value, :bytes, 2
end
class RpbIndexResp
include Beefcake::Message
repeated :keys, :bytes, 1
end
buf_count = 1_000
bufs = buf_count.times.map do |t|
key = ('bees' * 10) + rand(36**6).to_s(36)
keys = [key] * 100
e = RpbIndexResp.new(keys: keys).encode.to_s
l = [e.length].pack("N")
l + e
end.join('')
puts "gc"
pp GC.start
puts "made bufs (it's a #{bufs.bytesize} byte string), press enter to deserialize"
gets
resps = []
cursor = 0
buf_count.times do
l = bufs[cursor, 4].unpack('N').first
cursor += 4
buf = bufs[cursor, l]
m = RpbIndexResp.decode(buf)
cursor += l
resps << m
end
puts "got #{resps.length} results out"
puts "press enter to pry"
gets
binding.pry
puts "press enter to gc"
gets
resps = nil
GC.start
require 'benchmark'
require 'yaml'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'riak'
# require 'riak/test_server'
puts "Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
puts Time.now.to_s
client = Riak::Client.new pb_port: 8087
client.protocol = :pbc
puts "press enter to get index"
gets
result = client.get_index('mooltiget', '$bucket', '_')
puts "press enter to see results"
gets
puts result.length
result = nil
puts "press enter to quit"
gets
require 'benchmark'
require 'yaml'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'riak'
# require 'riak/test_server'
puts "Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
puts Time.now.to_s
count = ENV['OBJECT_COUNT'].to_i
puts "Count #{count}"
client = Riak::Client.new pb_port: 8087
client.protocol = :pbc
bucket = client.bucket 'mooltiget'
keys = (0..count).map(&:to_s)
puts "Inserting #{count} key value pairs"
keys.each do |n|
if n % 100 == 0
print "\r#{n}"
end
obj = bucket.get_or_new n.to_s
obj.content_type = 'text/plain'
obj.data = n.to_s
obj.store
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment