Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (42 sloc) 1.77 KB
import locust
import gevent
import random
from clients import HTTPClient
from gevent import wsgi
# Defines the behaviour of a locust (aka a website user :)
def website_user(name):
c = HTTPClient('http://localhost:8088')
for i in range(0, 10):
# Request the fast page, wait for the response
c.get('/fast', name='Fast page')
# Think for 5 seconds
# Do a few more requests
c.get('/slow', name='Slow page')
c.get('/consistent', name='Consistent page')
# End of function, locust dies.
# Simple WSGI server simulating fast and slow responses.
def test_server(env, start_response):
if env['PATH_INFO'] == '/fast':
start_response('200 OK', [('Content-Type', 'text/html')])
gevent.sleep(random.choice([0.1, 0.2, 0.3]))
return ["This is a fast response"]
if env['PATH_INFO'] == '/slow':
start_response('200 OK', [('Content-Type', 'text/html')])
gevent.sleep(random.choice([0.5, 1, 1.5]))
return ["This is a slow response"]
if env['PATH_INFO'] == '/consistent':
start_response('200 OK', [('Content-Type', 'text/html')])
return ["This is a consistent response"]
start_response('404 Not Found', [('Content-Type', 'text/html')])
return ['Not Found']
# Start the test server that will be our website under test
wsgi.WSGIServer(('', 8088), test_server).start()
# Start a web server where you can control the swarming
# from a web-based UI (recommended).
# Open http://localhost:8089 to start the test.
locust.prepare_swarm_from_web(website_user, hatch_rate=5, max=20)
# Immediately start swarming and print statistics to stdout every 1s
#locust.swarm(website_user, hatch_rate=4, max=10)