Search code examples
pythonweb-testinglocust

Locust worker starts doing requests before master finished wait for all workers


Could you please help me to find issue in my code? Or maybe this is a bug in Locust?

What happens it that if I start master (with options that it is supposed to wait for 2 workers) and one worker, worker starts doing requests even before starting another worker. I have found out that if I start worker with 0 users, it works as expected. But still, I'm now pretty unsure about the code.

Master code (source):

        env.create_master_runner(
            master_bind_host=args.master_bind_host,
            master_bind_port=args.master_bind_port,
        )

        while len(env.runner.clients.ready + env.runner.clients.running + env.runner.clients.spawning) < args.expect_workers:
            logging.info("Waiting for worker to become running, %s of %s connected - %s",
                         len(env.runner.clients.ready + env.runner.clients.running + env.runner.clients.spawning), args.expect_workers, ','.join([i.state for i in env.runner.clients.values()]))
            time.sleep(1)

        # Start the test
        logging.info("Starting master Locust runer")
        env.runner.start(args.num_clients, spawn_rate=args.hatch_rate)

        # Wait configured time and quit the test
        time.sleep(args.test_duration)
        gevent.spawn(lambda: env.runner.quit())

        # Wait for the greenlets to finish
        env.runner.greenlet.join()
        logging.info("Master Locust run finished")

Client code (source):

        env.create_worker_runner(
            master_host = args.master_host,
            master_port = args.master_port,
        )

        # Start the test
        logging.info("Starting worker Locust runner")
        env.runner.start(args.num_clients, spawn_rate=args.hatch_rate)

        # Wait for the greenlets to finish
        env.runner.greenlet.join()
        logging.info("Worker Locust run finished")

When I start client (even without master running), I get:

$ ./example.py --locust-worker-runner --locust-worker-master-host localhost --locust-num-clients 1 -d
DEBUG:root:Args: Namespace(locust_local_runner=True, locust_master_runner=False, locust_worker_runner=True, expect_workers=1, master_host='localhost', num_clients=1, hatch_rate=10, host='http://rbac.qa.svc:8080', stop_timeout=10, test_duration=100, test_requests=0, test_url_suffix='/api/rbac/v1', status_data_file='/tmp/status-data.json', debug=True)
Running with host = http://rbac.qa.svc:8080, num_clients = 1, hatch_rate = 10, duration = 100 / requests = 0
DEBUG:locust.runners:Updating state to 'spawning', old state was 'ready'
INFO:locust.runners:Spawning 1 users at the rate 10 users/s (0 users already running)...
INFO:locust.runners:All users spawned: TheApicurio: 1 (1 total running)
DEBUG:locust.runners:Updating state to 'running', old state was 'spawning'
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): google.com:80
DEBUG:urllib3.connectionpool:http://google.com:80 "GET / HTTP/1.1" 302 321
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): www.google.com:80
DEBUG:urllib3.connectionpool:http://www.google.com:80 "GET /sorry/index?continue=http://google.com/&q=EgTV0yuBGLLwkv4FIhkA8aeDSzLUElFEtFy9IvRfwQsqzVkKcWfcMgFy HTTP/1.1" 429 2786
DEBUG:root:Finished http://www.google.com/sorry/index?continue=http://google.com/&q=EgTV0yuBGLLwkv4FIhkA8aeDSzLUElFEtFy9IvRfwQsqzVkKcWfcMgFy with 429 in 0:00:00.106316
DEBUG:urllib3.connectionpool:http://google.com:80 "GET / HTTP/1.1" 302 321
[...]

I have:

$ python --version
Python 3.9.0
$ pip freeze | sort
certifi==2020.11.8
chardet==3.0.4
click==7.1.2
ConfigArgParse==1.2.3
deepdiff==5.0.2
-e [email protected]:redhat-performance/opl.git@197359b87b786e4db94d226baa130af752d02f70#egg=opl_rhcloud_perf_team
Flask==1.1.2
Flask-BasicAuth==0.2.0
future==0.18.2
gevent==20.9.0
geventhttpclient==1.4.4
geventhttpclient-wheels==1.3.1.dev2
greenlet==0.4.17
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
junitparser==1.6.1
kafka-python==2.0.2
locust==1.4.1
MarkupSafe==1.1.1
msgpack==1.0.0
numpy==1.19.4
ordered-set==4.0.2
psutil==5.7.3
psycopg2-binary==2.8.6
PyYAML==5.3.1
pyzmq==20.0.0
requests==2.25.0
scipy==1.5.3
six==1.15.0
tabulate==0.8.7
urllib3==1.26.2
Werkzeug==1.0.1
zope.event==4.5.0
zope.interface==5.2.0

Solution

  • OK, so I have solved it - I should not run env.runner.start(...) on a worker runner code. Worker is managed by master which spawns "users" on it.