1. from square_align_list_perf_as_package import UserTest
    2. print(UserTest)
    3. import gevent
    4. from locust import HttpUser, task, between
    5. from locust.env import Environment
    6. from locust.stats import stats_printer, stats_history
    7. from locust.log import setup_logging
    8. setup_logging("DEBUG", None)
    9. def master():
    10. master_env = Environment(user_classes=[UserTest])
    11. master_env.create_master_runner()
    12. # 启动一个greenlet,定期输出当前统计信息
    13. gevent.spawn(stats_printer(master_env.stats))
    14. master_env.runner.start(100, spawn_rate=10)
    15. gevent.spawn_later(10, lambda: master_env.runner.quit()))
    16. master_env.runner.greenlet.join()
    17. if __name__ == "__main__":
    18. master()
    1. from square_align_list_perf_as_package import UserTest
    2. print(UserTest)
    3. import gevent
    4. from locust import HttpUser, task, between
    5. from locust.env import Environment
    6. from locust.stats import stats_printer, stats_history
    7. from locust.log import setup_logging
    8. setup_logging("DEBUG", None)
    9. def worker():
    10. env = Environment(user_classes=[UserTest])
    11. env.create_worker_runner(master_host="0.0.0.0", master_port=5557)
    12. env.runner.start_worker(user_classes_count={"UserTest": 50})
    13. env.runner.heartbeat()
    14. env.runner.worker()
    15. env.runner.stats_reporter()
    16. env.runner.greenlet.join()
    17. if __name__ == "__main__":
    18. print("main")
    19. worker()