A dip with performance test lib Locust

Locust is a Python lib for performance test. Here is a first dip with locust with sample codes.

Installation

ⓑ>pip install locust pyzmq

The Sample Case

ⓑ>cat http_bare_visit.py
from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):

@task(1)
def bare_visit(self):
self.client.get("/")



class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 3000
max_wait = 6000
 ⓑ>

Run A Performance Test

ⓑ>locust -f ./http_bare_visit.py  --host=http://jenkins.maxwu.me
[2017-03-06 01:23:44,842] MaxWudeMacBook-Pro.local/INFO/locust.main: Starting web monitor at *:8089
[2017-03-06 01:23:44,842] MaxWudeMacBook-Pro.local/INFO/locust.main: Starting Locust 0.7.5
[2017-03-06 01:24:24,914] MaxWudeMacBook-Pro.local/INFO/locust.runners: Hatching and swarming 10 clients at the rate 1 clients/s...
[2017-03-06 01:24:34,939] MaxWudeMacBook-Pro.local/INFO/locust.runners: All locusts hatched: WebsiteUser: 10

Open browser on http://localhost:8089 and configure the simulation size and hatch rate. When the test execution starts, the GUI will provides statistic data.

Press Ctrl-C on terminal to stop the runner process. The data report is available on terminal console, too.

[2017-03-06 01:29:10,073] MaxWudeMacBook-Pro.local/ERROR/stderr: KeyboardInterrupt
[2017-03-06 01:29:10,074] MaxWudeMacBook-Pro.local/INFO/locust.main: Shutting down (exit code 0), bye.
Name # reqs # fails Avg Min Max | Median req/s
--------------------------------------------------------------------------------------------------------------------------------------------
GET / 106 1(0.93%) 346 179 501 | 350 2.00
--------------------------------------------------------------------------------------------------------------------------------------------
Total 106 1(0.94%) 2.00

Percentage of the requests completed within given times
Name # reqs 50% 66% 75% 80% 90% 95% 98% 99% 100%
--------------------------------------------------------------------------------------------------------------------------------------------
GET / 106 350 350 360 360 390 400 440 500 501
--------------------------------------------------------------------------------------------------------------------------------------------

Error report
# occurences Error
--------------------------------------------------------------------------------------------------------------------------------------------
1 GET /: "ConnectionError(ProtocolError('Connection aborted.', error(54, 'Connection reset by peer')),)"
--------------------------------------------------------------------------------------------------------------------------------------------

 ⓑ>

[EOF]