Class: RedisClusterCacheBenchmark::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_cluster_cache_benchmark/worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Worker

Returns a new instance of Worker.



11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#load_option(key, default_value = nil) ⇒ Object



21
22
23
24
25
# 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

#loggerObject



27
28
29
30
31
32
33
# 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_clientObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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

#runObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# 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