forked from redis/redis-rb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Verkhovsky
committed
May 8, 2009
1 parent
3095072
commit b14017f
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'fileutils' | ||
|
||
def run_in_background(command) | ||
fork { system command } | ||
end | ||
|
||
def with_all_segments(&block) | ||
0.upto(9) do |segment_number| | ||
block_size = 100000 | ||
start_index = segment_number * block_size | ||
end_index = start_index + block_size - 1 | ||
block.call(start_index, end_index) | ||
end | ||
end | ||
|
||
#with_all_segments do |start_index, end_index| | ||
# puts "Initializing keys from #{start_index} to #{end_index}" | ||
# system "ruby worker.rb initialize #{start_index} #{end_index} 0" | ||
#end | ||
|
||
with_all_segments do |start_index, end_index| | ||
run_in_background "ruby worker.rb write #{start_index} #{end_index} 10" | ||
run_in_background "ruby worker.rb read #{start_index} #{end_index} 1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
BENCHMARK_ROOT = File.dirname(__FILE__) | ||
REDIS_ROOT = File.join(BENCHMARK_ROOT, "..", "lib") | ||
|
||
$: << REDIS_ROOT | ||
require 'redis' | ||
require 'benchmark' | ||
|
||
def show_usage | ||
puts <<-EOL | ||
Usage: worker.rb [read:write] <start_index> <end_index> <sleep_msec> | ||
EOL | ||
end | ||
|
||
def shift_from_argv | ||
value = ARGV.shift | ||
unless value | ||
show_usage | ||
exit -1 | ||
end | ||
value | ||
end | ||
|
||
operation = shift_from_argv.to_sym | ||
start_index = shift_from_argv.to_i | ||
end_index = shift_from_argv.to_i | ||
sleep_msec = shift_from_argv.to_i | ||
sleep_duration = sleep_msec/1000.0 | ||
|
||
redis = Redis.new | ||
|
||
case operation | ||
when :initialize | ||
|
||
start_index.upto(end_index) do |i| | ||
redis[i] = 0 | ||
end | ||
|
||
when :clear | ||
|
||
start_index.upto(end_index) do |i| | ||
redis.delete(i) | ||
end | ||
|
||
when :read, :write | ||
|
||
puts "Starting to #{operation} at segment #{end_index + 1}" | ||
|
||
loop do | ||
t1 = Time.now | ||
start_index.upto(end_index) do |i| | ||
case operation | ||
when :read | ||
redis.get(i) | ||
when :write | ||
redis.incr(i) | ||
else | ||
raise "Unknown operation: #{operation}" | ||
end | ||
sleep sleep_duration | ||
end | ||
t2 = Time.now | ||
|
||
requests_processed = end_index - start_index | ||
time = t2 - t1 | ||
puts "#{t2.strftime("%H:%M")} [segment #{end_index + 1}] : Processed #{requests_processed} requests in #{time} seconds - #{(requests_processed/time).round} requests/sec" | ||
end | ||
|
||
else | ||
raise "Unknown operation: #{operation}" | ||
end | ||
|