Skip to content

Commit

Permalink
Adding 90th %ile to the stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
rsrinivasanNetflix committed May 28, 2017
1 parent 2e0ae9c commit 0e285cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,13 @@ def avg_response_time(self):
def median_response_time(self):
if not self.response_times:
return 0
return percentile_from_dict(self.num_requests, self.response_times, 50)

return median_from_dict(self.num_requests, self.response_times)
@property
def ninetieth_response_time(self):
if not self.response_times:
return 0
return percentile_from_dict(self.num_requests, self.response_times, 90)

@property
def current_rps(self):
Expand Down Expand Up @@ -411,18 +416,17 @@ def from_dict(cls, data):
def avg(values):
return sum(values, 0.0) / max(len(values), 1)

def median_from_dict(total, count):
def percentile_from_dict(total, count, percentile):
"""
total is the number of requests made
count is a dict {response_time: count}
"""
pos = (total - 1) / 2
pos = (total - 1) * (percentile / 100)
for k in sorted(six.iterkeys(count)):
if pos < count[k]:
return k
pos -= count[k]


global_stats = RequestStats()
"""
A global instance for holding the statistics. Should be removed eventually.
Expand Down
2 changes: 2 additions & 0 deletions locust/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ <h2>Change the locust count</h2>
<th class="stats_label numeric" href="#" data-sortkey="num_requests" title="Number of successful requests"># requests</th>
<th class="stats_label numeric" href="#" data-sortkey="num_failures" title="Number of failures"># fails</th>
<th class="stats_label numeric" href="#" data-sortkey="median_response_time" title="Median response time">Median (ms)</th>
<th class="stats_label numeric" href="#" data-sortkey="ninetieth_response_time" title="Ninetieth percentile response time">90%ile (ms)</th>
<th class="stats_label numeric" href="#" data-sortkey="avg_response_time" title="Average response time">Average (ms)</th>
<th class="stats_label numeric" href="#" data-sortkey="min_response_time" title="Min response time">Min (ms)</th>
<th class="stats_label numeric" href="#" data-sortkey="max_response_time" title="Max response time">Max (ms)</th>
Expand Down Expand Up @@ -206,6 +207,7 @@ <h1>Version</h1>
<td class="numeric"><%= this.num_requests %></td>
<td class="numeric"><%= this.num_failures %></td>
<td class="numeric"><%= Math.round(this.median_response_time) %></td>
<td class="numeric"><%= Math.round(this.ninetieth_response_time) %></td>
<td class="numeric"><%= Math.round(this.avg_response_time) %></td>
<td class="numeric"><%= this.min_response_time %></td>
<td class="numeric"><%= this.max_response_time %></td>
Expand Down
9 changes: 6 additions & 3 deletions locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import runners
from .cache import memoize
from .runners import MasterLocustRunner
from locust.stats import median_from_dict
from locust.stats import percentile_from_dict
from locust import __version__ as version

import logging
Expand Down Expand Up @@ -93,12 +93,13 @@ def request_stats_csv():
]

for s in chain(_sort_stats(runners.locust_runner.request_stats), [runners.locust_runner.stats.aggregated_stats("Total", full_request_history=True)]):
rows.append('"%s","%s",%i,%i,%i,%i,%i,%i,%i,%.2f' % (
rows.append('"%s","%s",%i,%i,%i,%i,%i,%i,%i,%i,%.2f' % (
s.method,
s.name,
s.num_requests,
s.num_failures,
s.median_response_time,
s.ninetieth_response_time,
s.avg_response_time,
s.min_response_time or 0,
s.max_response_time,
Expand Down Expand Up @@ -156,6 +157,7 @@ def request_stats():
"max_response_time": s.max_response_time,
"current_rps": s.current_rps,
"median_response_time": s.median_response_time,
"ninetieth_response_time": s.ninetieth_response_time,
"avg_content_length": s.avg_content_length,
})

Expand All @@ -178,7 +180,8 @@ def request_stats():
response_times[stats[i]["median_response_time"]] += stats[i]["num_requests"]

# calculate total median
stats[len(stats)-1]["median_response_time"] = median_from_dict(stats[len(stats)-1]["num_requests"], response_times)
stats[len(stats)-1]["median_response_time"] = percentile_from_dict(stats[len(stats)-1]["num_requests"], response_times, 50)
stats[len(stats)-1]["ninetieth_response_time"] = percentile_from_dict(stats[len(stats)-1]["num_requests"], response_times, 90)

is_distributed = isinstance(runners.locust_runner, MasterLocustRunner)
if is_distributed:
Expand Down

0 comments on commit 0e285cc

Please sign in to comment.