Skip to content

Instantly share code, notes, and snippets.

@colinsurprenant
Last active August 29, 2015 14:17
Show Gist options
  • Save colinsurprenant/f5dc5a165e6b5d80a046 to your computer and use it in GitHub Desktop.
Save colinsurprenant/f5dc5a165e6b5d80a046 to your computer and use it in GitHub Desktop.
bench
require "logstash/plugin"
require "logstash/event"
require "logstash/version"
require "benchmark"
module Tests
class NullOutput
def initialize
@plugin = LogStash::Plugin.lookup("output", "null").new
end
def run(obj)
@plugin.receive(obj)
end
end
class NullOutputPipelineWorker
def initialize
require "logstash/pipeline"
@pipeline = LogStash::Pipeline.new(<<-CONFIG)
output { null { } }
CONFIG
end
def run(event)
@pipeline.output(event)
end
end
class NullOutputPipelineQueue
def initialize
require "logstash/pipeline"
@pipeline = LogStash::Pipeline.new(<<-CONFIG)
output { null { } }
CONFIG
@queue = @pipeline.instance_eval { @filter_to_output }
@worker = Thread.new { @pipeline.outputworker }
end
def run(event)
@queue.push(event)
end
end
end
# 1.5 setup:
# - rake test:install-core
# - bin/plugin install logstash-output-null
# - bin/plugin install --development
#
# to run:
# USE_RUBY=1 bin/logstash rspec speed_spec.rb
Benchmark.bmbm(30) do |b|
tests = [ [Tests::NullOutput.new, 100_000_000], [Tests::NullOutputPipelineWorker.new, 10_000_000], [Tests::NullOutputPipelineQueue.new, 5_000_000] ]
tests.each do |test, count|
b.report(test.to_s) do
event = LogStash::Event.new
i = count
while i > 0
test.run(event)
i -= 1
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment