ports/benchmarks/py-locust/files/extra-EXAMPLES-multiple_hosts.py
Vinícius Zavam f20baa6ebd [NEW] benchmarks/py-locust: Python utility for doing distributed load tests
Locust is an easy-to-use, distributed, user load testing tool. It is
  intended for load-testing web sites (or other systems) and figuring out
  how many concurrent users a system can handle.

  The behavior of each locust (or test user if you will) is defined by you
  and the swarming process is monitored from a web UI in real-time. This
  will help you battle test and identify bottlenecks in your code before
  letting real users in.

  WWW: https://locust.io/

Approved by:	araujo (mentor), rene (mentor)
Sponsored by:	cleverbridge AG
Differential Revision:	https://reviews.freebsd.org/D18895
2019-01-20 12:54:30 +00:00

31 lines
847 B
Python

import os
from locust import HttpLocust, TaskSet, task
from locust.clients import HttpSession
class MultipleHostsLocust(HttpLocust):
abstract = True
def __init__(self, *args, **kwargs):
super(MultipleHostsLocust, self).__init__(*args, **kwargs)
self.api_client = HttpSession(base_url=os.environ["API_HOST"])
class UserTasks(TaskSet):
# but it might be convenient to use the @task decorator
@task
def index(self):
self.locust.client.get("/")
@task
def index_other_host(self):
self.locust.api_client.get("/stats/requests")
class WebsiteUser(MultipleHostsLocust):
"""
Locust user class that does requests to the locust web server running on localhost
"""
host = "http://127.0.0.1:8089"
min_wait = 2000
max_wait = 5000
task_set = UserTasks