def ramp_down(clients, hatch_stride): while True: if self.state != STATE_HATCHING: if self.num_clients < max_locusts: gevent.sleep(calibration_time) fail_ratio = RequestStats.sum_stats().fail_ratio if fail_ratio <= acceptable_fail: p = current_percentile(percent) if p <= response_time_limit: if hatch_stride <= precision: print "sweet spot found, ramping stopped!" return print "ramping up..." hatch_stride = max((hatch_stride/2),precision) clients += hatch_stride self.start_hatching(clients, self.hatch_rate) return ramp_up(clients, hatch_stride, True) print "ramping down..." hatch_stride = max((hatch_stride/2),precision) clients -= hatch_stride if clients > 0: self.start_hatching(clients, self.hatch_rate) else: print "WARNING: no responses met the ramping thresholds, check your ramp configuration, locustfile and \"--host\" address" print "ramping stopped!" return gevent.sleep(1)
def ramp_up(clients, hatch_stride, boundery_found=False): while True: if self.state != STATE_HATCHING: if self.num_clients >= max_locusts: print "ramp up stopped due to max locusts limit reached:", max_locusts client, hatch_stride = ramp_down_help(clients, hatch_stride) return ramp_down(clients, hatch_stride) gevent.sleep(calibration_time) fail_ratio = RequestStats.sum_stats().fail_ratio if fail_ratio > acceptable_fail: print "ramp up stopped due to acceptable fail ratio %d%% exceeded with fail ratio %d%%" % (acceptable_fail*100, fail_ratio*100) client, hatch_stride = ramp_down_help(clients, hatch_stride) return ramp_down(clients, hatch_stride) p = current_percentile(percent) if p >= response_time_limit: print "ramp up stopped due to percentile response times getting high:", p client, hatch_stride = ramp_down_help(clients, hatch_stride) return ramp_down(clients, hatch_stride) if boundery_found and hatch_stride <= precision: print "sweet spot found, ramping stopped!" return print "ramping up..." if boundery_found: hatch_stride = max((hatch_stride/2),precision) clients += hatch_stride self.start_hatching(clients, self.hatch_rate) gevent.sleep(1)
def ramp_up(clients, hatch_stride, boundery_found=False): while True: if locust_runner.state != STATE_HATCHING: if locust_runner.num_clients >= max_locusts: logger.info("Ramp up halted; Max locusts limit reached: %d" % max_locusts) return ramp_down(clients, hatch_stride) gevent.sleep(calibration_time) fail_ratio = RequestStats.sum_stats().fail_ratio if fail_ratio > acceptable_fail: logger.info("Ramp up halted; Acceptable fail ratio %d%% exceeded with fail ratio %d%%" % (acceptable_fail*100, fail_ratio*100)) return ramp_down(clients, hatch_stride) p = current_percentile(percent) if p >= response_time_limit: logger.info("Ramp up halted; Percentile response times getting high: %d" % p) return ramp_down(clients, hatch_stride) if boundery_found and hatch_stride <= precision: logger.info("Sweet spot found! Ramping stopped at %i locusts" % (locust_runner.num_clients)) return remove_listeners() logger.info("Ramping up...") if boundery_found: hatch_stride = max((hatch_stride/2),precision) clients += hatch_stride locust_runner.start_hatching(clients, locust_runner.hatch_rate) gevent.sleep(1)
def ramp_down(clients, hatch_stride): while True: if locust_runner.state != STATE_HATCHING: if locust_runner.num_clients < max_locusts: gevent.sleep(calibration_time) fail_ratio = RequestStats.sum_stats().fail_ratio if fail_ratio <= acceptable_fail: p = current_percentile(percent) if p <= response_time_limit: if hatch_stride <= precision: logger.info("Sweet spot found! Ramping stopped at %i locusts" % (locust_runner.num_clients)) return remove_listeners() logger.info("Ramping up...") hatch_stride = max((hatch_stride/2),precision) clients += hatch_stride locust_runner.start_hatching(clients, locust_runner.hatch_rate) return ramp_up(clients, hatch_stride, True) logger.info("Ramping down...") hatch_stride = max((hatch_stride/2),precision) clients -= hatch_stride if clients > 0: locust_runner.start_hatching(clients, locust_runner.hatch_rate) else: logger.warning("No responses met the ramping thresholds, check your ramp configuration, locustfile and \"--host\" address") logger.info("RAMING STOPPED") return remove_listeners() gevent.sleep(1)
def stats_csv(self): rows = [ ",".join([ '"Method"', '"Name"', '"# requests"', '"# failures"', '"Median response time"', '"Average response time"', '"Min response time"', '"Max response time"', '"Average Content Size"', '"Reqests/s"', ]) ] for s in chain(_sort_stats(self.request_stats), [RequestStats.sum_stats("Total", full_request_history=True)]): rows.append('"%s","%s",%i,%i,%i,%i,%i,%i,%i,%.2f' % ( s.method, s.name, s.num_reqs, s.num_failures, s.median_response_time, s.avg_response_time, s.min_response_time or 0, s.max_response_time, s.avg_content_length, s.total_rps, )) return "\n".join(rows)
def on_request_success_ramping(_, _1, response_time, _2): if is_distributed: response_times.append(response_time) else: response_times.append(response_time) # remove from the queue rps = RequestStats.sum_stats().current_rps if len(response_times) > rps*PERCENTILE_TIME_WINDOW: for i in xrange(len(response_times) - int(math.ceil(rps*PERCENTILE_TIME_WINDOW))): response_times.popleft()
def distribution_stats_csv(self): rows = [",".join(( '"Name"', '"# requests"', '"50%"', '"66%"', '"75%"', '"80%"', '"90%"', '"95%"', '"98%"', '"99%"', '"100%"', ))] for s in chain(_sort_stats(self.request_stats), [RequestStats.sum_stats("Total", full_request_history=True)]): if s.num_reqs: rows.append(s.percentile(tpl='"%s",%i,%i,%i,%i,%i,%i,%i,%i,%i,%i')) else: rows.append('"%s",0,"N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"' % s.name) return "\n".join(rows)