Class: AbCrunch::StrategyBestConcurrency
- Inherits:
-
Object
- Object
- AbCrunch::StrategyBestConcurrency
- Defined in:
- lib/abcrunch/strategy_best_concurrency.rb
Class Method Summary collapse
- .calc_threshold(baseline_latency, percent_buffer, max_latency) ⇒ Object
- .find_best_concurrency(page, baseline_result) ⇒ Object
- .run(page) ⇒ Object
Class Method Details
.calc_threshold(baseline_latency, percent_buffer, max_latency) ⇒ Object
4 5 6 |
# File 'lib/abcrunch/strategy_best_concurrency.rb', line 4 def self.calc_threshold(baseline_latency, percent_buffer, max_latency) [max_latency, baseline_latency * (1 + percent_buffer)].min end |
.find_best_concurrency(page, baseline_result) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/abcrunch/strategy_best_concurrency.rb', line 8 def self.find_best_concurrency(page, baseline_result) threshold_ms = calc_threshold(baseline_result.avg_response_time, page[:max_degradation_percent], page[:max_latency].to_f) AbCrunch::Logger.log :task, "Finding the max concurrency without degrading performance beyond a threshold" AbCrunch::Logger.log :info, "Threshold: #{threshold_ms} (ms)" AbCrunch::Logger.log :info, "Trying ever increasing concurrency until we bust the threshold" fmc_page = page.clone fmc_page[:concurrency] = 0 abr = baseline_result begin fmc_page[:concurrency] += 1 prev_result = abr abr = AbCrunch::BestRun.of_avg_response_time(fmc_page[:num_concurrency_runs], fmc_page) end while abr.avg_response_time < threshold_ms and fmc_page[:concurrency] < fmc_page[:num_requests] if abr.avg_response_time < threshold_ms return abr || baseline_result else fmc_page[:concurrency] -= 1 return prev_result || baseline_result end end |
.run(page) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/abcrunch/strategy_best_concurrency.rb', line 31 def self.run(page) page = AbCrunch::Config..merge(page) AbCrunch::Logger.log :strategy, "Strategy: find queries per second (QPS) at highest concurrency before latency degrades" AbCrunch::Logger.log :task, "Calculating Baseline (min average response time over multiple runs)" baseline_result = AbCrunch::BestRun.of_avg_response_time(page[:num_baseline_runs], page) best_result = find_best_concurrency(page, baseline_result) AbCrunch::Logger.log :progress, "Highest concurrency without degrading latency: #{best_result.[:concurrency]}" AbCrunch::Logger.log :result, "Queries Per Second (QPS): #{best_result.queries_per_second}" best_result.log best_result end |