Sha256: 7e62cd8304d8dd249f2dd20c8e6b332c9be822c73e5cab8364ad529fb172ab96

Contents?: true

Size: 1.26 KB

Versions: 26

Compression:

Stored size: 1.26 KB

Contents

# Run with
#
#   $ ruby -Ilib benchmarking/logging.rb
#

begin
  require "bench"
rescue LoadError
  $stderr.puts "`gem install bench` and try again."
  exit 1
end

require "redis"
require "logger"

def log(level, namespace = nil)
  logger = (namespace || Kernel).const_get(:Logger).new("/dev/null")
  logger.level = (namespace || Logger).const_get(level)
  logger
end

def stress(redis)
  redis.flushdb

  n = (ARGV.shift || 2000).to_i

  n.times do |i|
    key = "foo:#{i}"
    redis.set key, i
    redis.get key
  end
end

default = Redis.new

logging_redises = [
  Redis.new(:logger => log(:DEBUG)),
  Redis.new(:logger => log(:INFO)),
]

begin
  require "log4r"

  logging_redises += [
    Redis.new(:logger => log(:DEBUG, Log4r)),
    Redis.new(:logger => log(:INFO, Log4r)),
  ]
rescue LoadError
  $stderr.puts "Log4r not installed. `gem install log4r` if you want to compare it against Ruby's Logger (spoiler: it's much faster)."
end

benchmark "Default options (no logger)" do
  stress(default)
end

logging_redises.each do |redis|
  logger = redis.client.logger

  case logger
  when Logger
    level = Logger::SEV_LABEL[logger.level]
  when Log4r::Logger
    level = logger.levels[logger.level]
  end

  benchmark "#{logger.class} on #{level}" do
    stress(redis)
  end
end

run 10

Version data entries

26 entries across 25 versions & 8 rubygems

Version Path
finsync_redis-3.3.5 benchmarking/logging.rb
redis-3.3.5 benchmarking/logging.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/redis-3.3.3/benchmarking/logging.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/benchmarking/logging.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/benchmarking/logging.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/benchmarking/logging.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/redis-3.3.3/benchmarking/logging.rb
redis-3.3.3 benchmarking/logging.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.2/benchmarking/logging.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.1/benchmarking/logging.rb
redis-3.3.2 benchmarking/logging.rb
redis-3.3.1 benchmarking/logging.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/benchmarking/logging.rb
redis-3.3.0 benchmarking/logging.rb
discourse-redis-3.2.2 benchmarking/logging.rb
redis-3.2.2 benchmarking/logging.rb
redis-3.2.1 benchmarking/logging.rb
redis-3.2.0 benchmarking/logging.rb
redis-3.1.0 benchmarking/logging.rb
redis-3.0.7 benchmarking/logging.rb