本文整理汇总了Python中stats.RequestStats类的典型用法代码示例。如果您正苦于以下问题:Python RequestStats类的具体用法?Python RequestStats怎么用?Python RequestStats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestStats类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_hatching
def start_hatching(self, locust_count, hatch_rate):
self.num_clients = locust_count
slave_num_clients = locust_count / ((len(self.clients.ready) + len(self.clients.running)) or 1)
slave_hatch_rate = float(hatch_rate) / ((len(self.clients.ready) + len(self.clients.running)) or 1)
logger.info("Sending hatch jobs to %i ready clients" % (len(self.clients.ready) + len(self.clients.running)))
if not (len(self.clients.ready) + len(self.clients.running)):
logger.warning(
"You are running in distributed mode but have no slave servers connected. Please connect slaves prior to swarming."
)
return
if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
RequestStats.clear_all()
for client in self.clients.itervalues():
data = {
"hatch_rate": slave_hatch_rate,
"num_clients": slave_num_clients,
"num_requests": self.num_requests,
"host": self.host,
"stop_timeout": None,
}
self.server.send(Message("hatch", data, None))
RequestStats.global_start_time = time()
self.state = STATE_HATCHING
示例2: start_hatching
def start_hatching(self, locust_count=None, hatch_rate=None, wait=False):
if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
RequestStats.clear_all()
RequestStats.global_start_time = time()
self.exceptions = {}
# Dynamically changing the locust count
if self.state != STATE_INIT and self.state != STATE_STOPPED:
self.state = STATE_HATCHING
if self.num_clients > locust_count:
# Kill some locusts
kill_count = self.num_clients - locust_count
self.kill_locusts(kill_count)
elif self.num_clients < locust_count:
# Spawn some locusts
if hatch_rate:
self.hatch_rate = hatch_rate
spawn_count = locust_count - self.num_clients
self.spawn_locusts(spawn_count=spawn_count)
else:
if hatch_rate:
self.hatch_rate = hatch_rate
if locust_count:
self.spawn_locusts(locust_count, wait=wait)
else:
self.spawn_locusts(wait=wait)
示例3: ramp_down
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)
示例4: ramp_up
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)
示例5: ramp_up
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)
示例6: ramp_down
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)
示例7: stats_csv
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)
示例8: start_hatching
def start_hatching(self, locust_count, hatch_rate):
self.num_clients = locust_count
slave_num_clients = locust_count / ((len(self.clients.ready) + len(self.clients.running)) or 1)
slave_hatch_rate = float(hatch_rate) / ((len(self.clients.ready) + len(self.clients.running)) or 1)
print "Sending hatch jobs to %i ready clients" % (len(self.clients.ready) + len(self.clients.running))
if not (len(self.clients.ready)+len(self.clients.running)):
print "WARNING: You are running in distributed mode but have no slave servers connected."
print "Please connect slaves prior to swarming."
if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
RequestStats.clear_all()
for client in self.clients.itervalues():
msg = {"hatch_rate":slave_hatch_rate, "num_clients":slave_num_clients, "num_requests": self.num_requests, "host":self.host, "stop_timeout":None}
self.server.send({"type":"hatch", "data":msg})
RequestStats.global_start_time = time()
self.state = STATE_HATCHING
示例9: on_request_success_ramping
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()
示例10: distribution_stats_csv
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)
示例11: on_hatch_complete
def on_hatch_complete(count):
self.state = STATE_RUNNING
logger.info("Resetting stats\n")
RequestStats.reset_all()
示例12: on_hatch_complete
def on_hatch_complete(count):
self.state = STATE_RUNNING
print "Resetting stats\n"
RequestStats.reset_all()