Class: Alicorn::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/alicorn/profiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Profiler

Returns a new instance of Profiler.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/alicorn/profiler.rb', line 8

def initialize(options = {})
  @log_path     = options[:log_path]
  @min_workers  = options[:min_workers]
  @max_workers  = options[:max_workers]
  @target_ratio = options[:target_ratio]
  @buffer       = options[:buffer]
  @verbose      = options.delete(:verbose)

  @out          = options[:test] ? File.open("/dev/null") : STDOUT
  @worker_count = @max_workers
  @scaler = Scaler.new(options.merge(:log_path => nil))
  @alp    = LogParser.new(@log_path)
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def buffer
  @buffer
end

#log_pathObject

Returns the value of attribute log_path.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def log_path
  @log_path
end

#max_workersObject

Returns the value of attribute max_workers.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def max_workers
  @max_workers
end

#min_workersObject

Returns the value of attribute min_workers.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def min_workers
  @min_workers
end

#outObject

Returns the value of attribute out.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def out
  @out
end

#target_ratioObject

Returns the value of attribute target_ratio.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def target_ratio
  @target_ratio
end

#verboseObject

Returns the value of attribute verbose.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def verbose
  @verbose
end

#worker_countObject

Returns the value of attribute worker_count.



5
6
7
# File 'lib/alicorn/profiler.rb', line 5

def worker_count
  @worker_count
end

Instance Method Details

#profileObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/alicorn/profiler.rb', line 22

def profile
  samples = @alp.parse
  @out.puts "Profiling #{samples.count} samples"

  samples.each do |sample|
    connections = sample[:active].zip(sample[:queued]).map { |e| e.inject(:+) }
    if connections.max > @worker_count
      @out.puts "Overloaded! Ran #{@worker_count} and got #{connections.max} active + queued"
      @out.puts sample if @verbose
    end
    sig, count = @scaler.auto_scale(sample, @worker_count)
    @worker_count += count if sig == "TTIN"
    @worker_count -= count if sig == "TTOU"
  end
end