Class: LogStash::PerformanceMeter::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/lsperfm/core/run.rb

Constant Summary collapse

LOGSTASH_BIN =
File.join("bin", "logstash").freeze
INITIAL_MESSAGE =
">>> lorem ipsum start".freeze
LAST_MESSAGE =
">>> lorem ipsum stop".freeze
REFRESH_COUNT =
100

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, debug = false, logstash_home = Dir.pwd) ⇒ Runner

Returns a new instance of Runner.


21
22
23
24
# File 'lib/lsperfm/core/run.rb', line 21

def initialize(config, debug = false, logstash_home = Dir.pwd)
  @debug = debug
  @command = [File.join(logstash_home, LOGSTASH_BIN), "-f", config]
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.


19
20
21
# File 'lib/lsperfm/core/run.rb', line 19

def command
  @command
end

Class Method Details

.headersObject


53
54
55
# File 'lib/lsperfm/core/run.rb', line 53

def self.headers
  ["start time", "elapsed", "events", "avg tps", "best tps", "avg top 20% tps"]
end

.read_input_file(file_path) ⇒ Object


65
66
67
# File 'lib/lsperfm/core/run.rb', line 65

def self.read_input_file(file_path)
  IO.readlines(file_path).map(&:chomp)
end

Instance Method Details

#feed_input_events(io, events_count, lines, last_message) ⇒ Object


69
70
71
72
73
74
75
76
77
# File 'lib/lsperfm/core/run.rb', line 69

def feed_input_events(io, events_count, lines, last_message)
  loop_count = (events_count / lines.size).ceil # how many time we send the input file over
  (1..loop_count).each{lines.each {|line| io.puts(line)}}

  io.puts(last_message)
  io.flush

  loop_count * lines.size
end

#feed_input_with(required_events_count, required_run_time, input_lines, i) ⇒ Object


57
58
59
60
61
62
63
# File 'lib/lsperfm/core/run.rb', line 57

def feed_input_with(required_events_count, required_run_time, input_lines, i)
  if required_events_count > 0
    feed_input_events(i, [required_events_count, input_lines.size].max, input_lines, LAST_MESSAGE)
  else
    feed_input_interval(i, required_run_time, input_lines, LAST_MESSAGE)
  end
end

#run(required_events_count, required_run_time, input_lines) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lsperfm/core/run.rb', line 26

def run(required_events_count, required_run_time, input_lines)
  puts("launching #{command.join(" ")} #{required_events_count} #{required_run_time}") if @debug
  stats = LogStash::PerformanceMeter::Stats.new
  real_events_count = 0
  Open3.popen3(*@command) do |i, o, e|
    puts("sending initial event") if @debug
    start_time = Benchmark.realtime do
      i.puts(INITIAL_MESSAGE)
      i.flush

      puts("waiting for initial event") if @debug
      expect_output(o, /#{INITIAL_MESSAGE}/)
    end

    puts("starting output reader thread") if @debug
    reader = stats.detach_output_reader(o, /#{LAST_MESSAGE}/)
    puts("starting feeding input") if @debug

    elapsed = Benchmark.realtime do
      real_events_count = feed_input_with(required_events_count, required_run_time, input_lines, i)
      puts("waiting for output reader to complete") if @debug
      reader.join
    end
    { :percentile => percentile(stats.stats, 0.80) , :elapsed => elapsed, :events_count => real_events_count, :start_time => start_time }
  end
end