class RedisClusterCacheBenchmark::Worker
Public Class Methods
new(options)
click to toggle source
# File lib/redis_cluster_cache_benchmark/worker.rb, line 11 def initialize(options) @options = options @repeat = (options[:repeat] || 1).to_i @worker_no = (options[:worker_no] || 0).to_i @classname = load_option(:classname, "RedisClusterCacheBenchmark::MemoryStorage") @log_path = load_option(:log_path) @config_path = load_option(:config_path) @scenario = load_option(:scenario) end
Public Instance Methods
load_option(key, default_value = nil)
click to toggle source
# File lib/redis_cluster_cache_benchmark/worker.rb, line 21 def load_option(key, default_value = nil) r = @options[key] r = nil if r && r.empty? r || default_value end
logger()
click to toggle source
# File lib/redis_cluster_cache_benchmark/worker.rb, line 27 def logger unless @logger @logger = Logger.new(@log_path || $stdout) @logger.level = Logger::INFO end @logger end
new_client()
click to toggle source
# File lib/redis_cluster_cache_benchmark/worker.rb, line 35 def new_client config = @config_path ? YAML.load_file_with_erb(@config_path) : {host: "127.0.0.1", port: 6379} case @classname when 'Redis', 'RedisWmrs' then klass = Object.const_get(@classname) original = klass.new(config) original.client.logger = logger return LoggingClient.new(original, logger) when "RedisClusterCacheBenchmark::MemoryStorage" then original = RedisClusterCacheBenchmark::MemoryStorage.new original.logger = logger return LoggingClient.new(original, logger) else raise "Unknown classname: #{@classname.inspect}" end end
run()
click to toggle source
# File lib/redis_cluster_cache_benchmark/worker.rb, line 54 def run $client = new_client len = @repeat.to_s.length logger.info("[RSS] starting #{@worker_no}: %d KB" % `ps -o rss= -p #{Process.pid}`.to_i) @repeat.times do |idx| begin load(@scenario) ensure logger.info("No.%3d scenario %*d/%*d finished" % [@worker_no, len, idx + 1, len, @repeat]) end end logger.info("[RSS] completed #{@worker_no}: %d KB" % `ps -o rss= -p #{Process.pid}`.to_i) end