简体   繁体   中英

Get Docker Container's Name from within Python Locust Loadtest

I am using Python, Docker, and Locust to load test a service I am working on. I have some test data I need to partition uniquely between how ever many docker containers I spin up dynamically. Locust gives all of it's worker containers a name styled as "worker_N". How can I get the worker name assigned to the container by checking inside the python script itself? I am using docker compose to spin up the containers, so I can't use the similar solution provided here .

Depending on exactly what it is you're trying to do, you could set a hostname or maybe an alias for each worker. (Locust uses hostname + a GUID for the name of the workers.) If you need to access each worker somehow, you could set the hostname to include an IP address. Just an idea.

To address your original question more directly, there are also other ways to access hostname, such as in Python code (like Locust does).

One last option would be to use the master do push the data you need to each worker using Locust's messages feature . Then you only need to ensure the master has access to whatever data you want distributed to the workers and it can divvy it up to however many workers are connected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM