Class: Alicorn::Profiler
- Inherits:
-
Object
- Object
- Alicorn::Profiler
- Defined in:
- lib/alicorn/profiler.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#log_path ⇒ Object
Returns the value of attribute log_path.
-
#max_workers ⇒ Object
Returns the value of attribute max_workers.
-
#min_workers ⇒ Object
Returns the value of attribute min_workers.
-
#out ⇒ Object
Returns the value of attribute out.
-
#target_ratio ⇒ Object
Returns the value of attribute target_ratio.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#worker_count ⇒ Object
Returns the value of attribute worker_count.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Profiler
constructor
A new instance of Profiler.
- #profile ⇒ Object
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( = {}) @log_path = [:log_path] @min_workers = [:min_workers] @max_workers = [:max_workers] @target_ratio = [:target_ratio] @buffer = [:buffer] @verbose = .delete(:verbose) @out = [:test] ? File.open("/dev/null") : STDOUT @worker_count = @max_workers @scaler = Scaler.new(.merge(:log_path => nil)) @alp = LogParser.new(@log_path) end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
5 6 7 |
# File 'lib/alicorn/profiler.rb', line 5 def buffer @buffer end |
#log_path ⇒ Object
Returns the value of attribute log_path.
5 6 7 |
# File 'lib/alicorn/profiler.rb', line 5 def log_path @log_path end |
#max_workers ⇒ Object
Returns the value of attribute max_workers.
5 6 7 |
# File 'lib/alicorn/profiler.rb', line 5 def max_workers @max_workers end |
#min_workers ⇒ Object
Returns the value of attribute min_workers.
5 6 7 |
# File 'lib/alicorn/profiler.rb', line 5 def min_workers @min_workers end |
#out ⇒ Object
Returns the value of attribute out.
5 6 7 |
# File 'lib/alicorn/profiler.rb', line 5 def out @out end |
#target_ratio ⇒ Object
Returns the value of attribute target_ratio.
5 6 7 |
# File 'lib/alicorn/profiler.rb', line 5 def target_ratio @target_ratio end |
#verbose ⇒ Object
Returns the value of attribute verbose.
5 6 7 |
# File 'lib/alicorn/profiler.rb', line 5 def verbose @verbose end |
#worker_count ⇒ Object
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
#profile ⇒ Object
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 |