-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Retrieving response time on Master while execution is going on through custom code in no-web mode #1351
Comments
In Locust 1.0 (haven't been released yet, but works in master) you can do this: import gevent
from locust import HttpUser, events, task, constant
from locust.env import Environment
from locust.runners import LocalRunner, MasterRunner
class MyUser(HttpUser):
wait_time = constant(1)
@task
def t(self):
self.client.get("/")
greenlet = [None]
@events.init.add_listener
def on_init(environment: Environment, **kw):
if isinstance(environment.runner, (MasterRunner, LocalRunner)):
def stats_thread():
while True:
gevent.sleep(1)
# here we can access to current stats in the master node through environment.stats
print("Total requests made", environment.stats.total.num_requests)
greenlet[0] = gevent.spawn(stats_thread)
# kill our stats greenlet when locust quits
@events.quitting.add_listener
def on_quitting(**kw):
if greenlet[0]:
gevent.kill(greenlet[0]) EDIT: It's possible to do this is the latest released version as well but you'd have to retrieve references to from locust.runners import locust_runner
from locust.stats import global_stats The init event is also new, but you could start the greenlet at the module level instead. |
@heyman Thanks for the code and the details. I am using 0.12.2 and looks like few import classes are not available in this version. Which version is recommended to incorporate the above code in my script? |
See the additional info I added to my post. (Below "EDIT:" which I added now ) |
Does Locust has any function which can be used to read the request statistics on Master node in distributed mode while the execution is in progress. I want to read live stats and store them into a DB. I don't want to use the csv that gets generated at the end of the execution.
Note: The test will be in no-web mode.
The text was updated successfully, but these errors were encountered: