diff options
author | Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org> | 2025-06-12 18:51:22 -0400 |
---|---|---|
committer | Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org> | 2025-06-12 20:21:40 -0400 |
commit | cadda769f93f6743398bbeb88b8c3c2df0423535 (patch) | |
tree | 727d8655c9e0c4067254803e209fdb85a1205c3d /benchmarks/py-locust/files | |
parent | benchmarks/py-locust-cloud: New port: Hosted version of Locust that allows yo... (diff) |
benchmarks/py-locust: Upgrade to 2.37.10
* Pet portclippy/portfmt.
* Add distribution file for examples and test scripts (the release
file does not include them, but includes the web UI which the
repository does not have).
* Remove examples (they are now incompatible with the new version of
Locust).
* Include updated examples from the repository.
* Prefer to generate pkg-plist manually instead of relying on autoplist
(since the sample scripts are included manually, it is preferable to
manually generate the pkg-plist).
* Change distutils in favor of pep517.
* Fix binding in all interfaces when --web-host is set to '*'.
ChangeLog: https://github.com/locustio/locust/compare/0.11.0...2.37.10
PR: 287027
Approved by: acm (mentor)
Approved by: maintainer timeout (20 days)
Diffstat (limited to 'benchmarks/py-locust/files')
10 files changed, 11 insertions, 380 deletions
diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-basic.py b/benchmarks/py-locust/files/extra-EXAMPLES-basic.py deleted file mode 100644 index c34610e8df8e..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-basic.py +++ /dev/null @@ -1,26 +0,0 @@ -from locust import HttpLocust, TaskSet, task - - -def index(l): - l.client.get("/") - -def stats(l): - l.client.get("/stats/requests") - -class UserTasks(TaskSet): - # one can specify tasks like this - tasks = [index, stats] - - # but it might be convenient to use the @task decorator - @task - def page404(self): - self.client.get("/does_not_exist") - -class WebsiteUser(HttpLocust): - """ - 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 diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_sequence_test.py b/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_sequence_test.py deleted file mode 100644 index b780c67e9879..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_sequence_test.py +++ /dev/null @@ -1,50 +0,0 @@ -# This locust test script example will simulate a user -# browsing the Locust documentation on https://docs.locust.io/ - -import random -from locust import HttpLocust, TaskSquence, seq_task, task -from pyquery import PyQuery - - -class BrowseDocumentationSequence(TaskSquence): - def on_start(self): - self.urls_on_current_page = self.toc_urls - - # assume all users arrive at the index page - @seq_task(1) - def index_page(self): - r = self.client.get("/") - pq = PyQuery(r.content) - link_elements = pq(".toctree-wrapper a.internal") - self.toc_urls = [ - l.attrib["href"] for l in link_elements - ] - - @seq_task(2) - @task(50) - def load_page(self, url=None): - url = random.choice(self.toc_urls) - r = self.client.get(url) - pq = PyQuery(r.content) - link_elements = pq("a.internal") - self.urls_on_current_page = [ - l.attrib["href"] for l in link_elements - ] - - @seq_task(3) - @task(30) - def load_sub_page(self): - url = random.choice(self.urls_on_current_page) - r = self.client.get(url) - - -class AwesomeUser(HttpLocust): - task_set = BrowseDocumentationSequence - host = "https://docs.locust.io/en/latest/" - - # we assume someone who is browsing the Locust docs, - # generally has a quite long waiting time (between - # 20 and 600 seconds), since there's a bunch of text - # on each page - min_wait = 20 * 1000 - max_wait = 600 * 1000 diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py b/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py deleted file mode 100644 index b8a42a7c2bd1..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py +++ /dev/null @@ -1,49 +0,0 @@ -# This locust test script example will simulate a user -# browsing the Locust documentation on https://docs.locust.io/ - -import random -from locust import HttpLocust, TaskSet, task -from pyquery import PyQuery - - -class BrowseDocumentation(TaskSet): - def on_start(self): - # assume all users arrive at the index page - self.index_page() - self.urls_on_current_page = self.toc_urls - - @task(10) - def index_page(self): - r = self.client.get("/") - pq = PyQuery(r.content) - link_elements = pq(".toctree-wrapper a.internal") - self.toc_urls = [ - l.attrib["href"] for l in link_elements - ] - - @task(50) - def load_page(self, url=None): - url = random.choice(self.toc_urls) - r = self.client.get(url) - pq = PyQuery(r.content) - link_elements = pq("a.internal") - self.urls_on_current_page = [ - l.attrib["href"] for l in link_elements - ] - - @task(30) - def load_sub_page(self): - url = random.choice(self.urls_on_current_page) - r = self.client.get(url) - - -class AwesomeUser(HttpLocust): - task_set = BrowseDocumentation - host = "https://docs.locust.io/en/latest/" - - # we assume someone who is browsing the Locust docs, - # generally has a quite long waiting time (between - # 20 and 600 seconds), since there's a bunch of text - # on each page - min_wait = 20 * 1000 - max_wait = 600 * 1000 diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py b/benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py deleted file mode 100644 index fad47c3174a6..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py +++ /dev/null @@ -1,51 +0,0 @@ -from locust import HttpLocust, TaskSet, task -import random - -def index(l): - l.client.get("/") - -def stats(l): - l.client.get("/stats/requests") - -class UserTasks(TaskSet): - # one can specify tasks like this - tasks = [index, stats] - - # but it might be convenient to use the @task decorator - @task - def page404(self): - self.client.get("/does_not_exist") - -class WebsiteUser(HttpLocust): - """ - Locust user class that does requests to the locust web server running on localhost - """ - host = "http://127.0.0.1:8089" - # Most task inter-arrival times approximate to exponential distributions - # We will model this wait time as exponentially distributed with a mean of 1 second - wait_function = lambda self: random.expovariate(1)*1000 # *1000 to convert to milliseconds - task_set = UserTasks - -def strictExp(min_wait,max_wait,mu=1): - """ - Returns an exponentially distributed time strictly between two bounds. - """ - while True: - x = random.expovariate(mu) - increment = (max_wait-min_wait)/(mu*6.0) - result = min_wait + (x*increment) - if result<max_wait: - break - return result - -class StrictWebsiteUser(HttpLocust): - """ - Locust user class that makes exponential requests but strictly between two bounds. - """ - host = "http://127.0.0.1:8089" - wait_function = lambda self: strictExp(self.min_wait, self.max_wait)*1000 - task_set = UserTasks - - - - diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-custom_xmlrpc_client.py b/benchmarks/py-locust/files/extra-EXAMPLES-custom_xmlrpc_client.py deleted file mode 100644 index f117acd7790a..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-custom_xmlrpc_client.py +++ /dev/null @@ -1,54 +0,0 @@ -import time -import xmlrpclib - -from locust import Locust, TaskSet, events, task - - -class XmlRpcClient(xmlrpclib.ServerProxy): - """ - Simple, sample XML RPC client implementation that wraps xmlrpclib.ServerProxy and - fires locust events on request_success and request_failure, so that all requests - gets tracked in locust's statistics. - """ - def __getattr__(self, name): - func = xmlrpclib.ServerProxy.__getattr__(self, name) - def wrapper(*args, **kwargs): - start_time = time.time() - try: - result = func(*args, **kwargs) - except xmlrpclib.Fault as e: - total_time = int((time.time() - start_time) * 1000) - events.request_failure.fire(request_type="xmlrpc", name=name, response_time=total_time, exception=e) - else: - total_time = int((time.time() - start_time) * 1000) - events.request_success.fire(request_type="xmlrpc", name=name, response_time=total_time, response_length=0) - # In this example, I've hardcoded response_length=0. If we would want the response length to be - # reported correctly in the statistics, we would probably need to hook in at a lower level - - return wrapper - - -class XmlRpcLocust(Locust): - """ - This is the abstract Locust class which should be subclassed. It provides an XML-RPC client - that can be used to make XML-RPC requests that will be tracked in Locust's statistics. - """ - def __init__(self, *args, **kwargs): - super(XmlRpcLocust, self).__init__(*args, **kwargs) - self.client = XmlRpcClient(self.host) - - -class ApiUser(XmlRpcLocust): - - host = "http://127.0.0.1:8877/" - min_wait = 100 - max_wait = 1000 - - class task_set(TaskSet): - @task(10) - def get_time(self): - self.client.get_time() - - @task(5) - def get_random_number(self): - self.client.get_random_number(0, 100) diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py b/benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py deleted file mode 100644 index 6f8f66baa5ca..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py +++ /dev/null @@ -1,25 +0,0 @@ -# locustfile.py - -from locust import HttpLocust, TaskSet, task - -USER_CREDENTIALS = [ - ("user1", "password"), - ("user2", "password"), - ("user3", "password"), -] - -class UserBehaviour(TaskSet): - def on_start(self): - if len(USER_CREDENTIALS) > 0: - user, passw = USER_CREDENTIALS.pop() - self.client.post("/login", {"username":user, "password":passw}) - - @task - def some_task(self): - # user should be logged in here (unless the USER_CREDENTIALS ran out) - self.client.get("/protected/resource") - -class User(HttpLocust): - task_set = UserBehaviour - min_wait = 5000 - max_wait = 60000 diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-events.py b/benchmarks/py-locust/files/extra-EXAMPLES-events.py deleted file mode 100644 index 7b1de7fafee2..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-events.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -This is an example of a locustfile that uses Locust's built in event hooks to -track the sum of the content-length header in all successful HTTP responses -""" - -from locust import HttpLocust, TaskSet, events, task, web - - -class MyTaskSet(TaskSet): - @task(2) - def index(l): - l.client.get("/") - - @task(1) - def stats(l): - l.client.get("/stats/requests") - -class WebsiteUser(HttpLocust): - host = "http://127.0.0.1:8089" - min_wait = 2000 - max_wait = 5000 - task_set = MyTaskSet - - -""" -We need somewhere to store the stats. - -On the master node stats will contain the aggregated sum of all content-lengths, -while on the slave nodes this will be the sum of the content-lengths since the -last stats report was sent to the master -""" -stats = {"content-length":0} - -def on_request_success(request_type, name, response_time, response_length): - """ - Event handler that get triggered on every successful request - """ - stats["content-length"] += response_length - -def on_report_to_master(client_id, data): - """ - This event is triggered on the slave instances every time a stats report is - to be sent to the locust master. It will allow us to add our extra content-length - data to the dict that is being sent, and then we clear the local stats in the slave. - """ - data["content-length"] = stats["content-length"] - stats["content-length"] = 0 - -def on_slave_report(client_id, data): - """ - This event is triggered on the master instance when a new stats report arrives - from a slave. Here we just add the content-length to the master's aggregated - stats dict. - """ - stats["content-length"] += data["content-length"] - -# Hook up the event listeners -events.request_success += on_request_success -events.report_to_master += on_report_to_master -events.slave_report += on_slave_report - -@web.app.route("/content-length") -def total_content_length(): - """ - Add a route to the Locust web app, where we can see the total content-length - """ - return "Total content-length recieved: %i" % stats["content-length"] diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-multiple_hosts.py b/benchmarks/py-locust/files/extra-EXAMPLES-multiple_hosts.py deleted file mode 100644 index b30585b37ce1..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-multiple_hosts.py +++ /dev/null @@ -1,31 +0,0 @@ -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 diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-semaphore_wait.py b/benchmarks/py-locust/files/extra-EXAMPLES-semaphore_wait.py deleted file mode 100644 index 563b89c95d63..000000000000 --- a/benchmarks/py-locust/files/extra-EXAMPLES-semaphore_wait.py +++ /dev/null @@ -1,25 +0,0 @@ -from locust import HttpLocust, TaskSet, task, events - -from gevent.coros import Semaphore -all_locusts_spawned = Semaphore() -all_locusts_spawned.acquire() - -def on_hatch_complete(**kw): - all_locusts_spawned.release() - -events.hatch_complete += on_hatch_complete - -class UserTasks(TaskSet): - def on_start(self): - all_locusts_spawned.wait() - self.wait() - - @task - def index(self): - self.client.get("/") - -class WebsiteUser(HttpLocust): - host = "http://127.0.0.1:8089" - min_wait = 2000 - max_wait = 5000 - task_set = UserTasks diff --git a/benchmarks/py-locust/files/patch-locust_main.py b/benchmarks/py-locust/files/patch-locust_main.py new file mode 100644 index 000000000000..fc7fc9d27587 --- /dev/null +++ b/benchmarks/py-locust/files/patch-locust_main.py @@ -0,0 +1,11 @@ +--- locust/main.py.orig 2025-06-12 22:34:12 UTC ++++ locust/main.py +@@ -454,7 +454,7 @@ See https://github.com/locustio/locust/wiki/Installati + sys.exit(1) + if options.web_host == "*": + # special check for "*" so that we're consistent with --master-bind-host +- web_host = "" ++ web_host = "0.0.0.0" + else: + web_host = options.web_host + if web_host: |