Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#331: Use rounded_response_time for min/max/total response times #558

Merged
merged 3 commits into from
Oct 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.box = "ubuntu/xenial32"
config.vm.network :forwarded_port, guest: 8089, host: 8089
config.vm.provision :shell, :path => "examples/vagrant/vagrant.sh"
end
end
4 changes: 2 additions & 2 deletions examples/vagrant/vagrant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Update and install some dependencies
apt-get -y update
apt-get -y install build-essential python-pip python-dev libev-dev libzmq-dev
apt-get -y install build-essential python-pip python-dev libev-dev libzmq-dev supervisor
cd /vagrant

pip install --use-mirrors pyzmq supervisor
Expand All @@ -15,4 +15,4 @@ pip install --use-mirrors pyzmq supervisor
python setup.py develop

# Starting supervisor which is configured to start Locust
supervisord -c examples/vagrant/supervisord.conf
supervisord -c examples/vagrant/supervisord.conf
3 changes: 2 additions & 1 deletion locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def _log_time_of_request(self, t):
self.last_request_timestamp = t

def _log_response_time(self, response_time):

self.total_response_time += response_time

if self.min_response_time is None:
Expand Down Expand Up @@ -460,7 +461,7 @@ def percentile(self, tpl=" %-" + str(STATS_NAME_WIDTH) + "s %8d %6d %6d %6d %6d
self.get_response_time_percentile(0.95),
self.get_response_time_percentile(0.98),
self.get_response_time_percentile(0.99),
self.max_response_time
self.get_response_time_percentile(1.00)
)

def _cache_response_times(self, t):
Expand Down
31 changes: 30 additions & 1 deletion locust/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_num_reqs_fails(self):
self.assertEqual(self.s.num_failures, 3)

def test_avg(self):
self.assertEqual(self.s.avg_response_time, 187.71428571428571428571428571429)
self.assertEqual(self.s.avg_response_time, 187.71428571428572)

def test_reset(self):
self.s.reset()
Expand Down Expand Up @@ -98,6 +98,35 @@ def test_aggregation(self):
self.assertEqual(s.num_failures, 3)
self.assertEqual(s.median_response_time, 38)
self.assertEqual(s.avg_response_time, 43.2)

def test_aggregation_with_rounding(self):
s1 = StatsEntry(self.stats, "round me!", "GET")
s1.log(122, 0) # (rounded 120) min
s1.log(992, 0) # (rounded 990) max
s1.log(142, 0) # (rounded 140)
s1.log(552, 0) # (rounded 550)
s1.log(557, 0) # (rounded 560)
s1.log(387, 0) # (rounded 390)
s1.log(557, 0) # (rounded 560)
s1.log(977, 0) # (rounded 980)

self.assertEqual(s1.num_requests, 8)
self.assertEqual(s1.median_response_time, 550)
self.assertEqual(s1.avg_response_time, 535.75)
self.assertEqual(s1.min_response_time, 122)
self.assertEqual(s1.max_response_time, 992)

def test_percentile_rounded_down(self):
s1 = StatsEntry(self.stats, "rounding down!", "GET")
s1.log(122, 0) # (rounded 120) min
actual_percentile = s1.percentile()
self.assertEqual(actual_percentile, " GET rounding down! 1 120 120 120 120 120 120 120 120 120")

def test_percentile_rounded_up(self):
s2 = StatsEntry(self.stats, "rounding up!", "GET")
s2.log(127, 0) # (rounded 130) min
actual_percentile = s2.percentile()
self.assertEqual(actual_percentile, " GET rounding up! 1 130 130 130 130 130 130 130 130 130")

def test_error_grouping(self):
# reset stats
Expand Down