【问题标题】:Locust while running as library with grpc client not outputting stats蝗虫作为库运行时 grpc 客户端不输出统计信息
【发布时间】:2022-01-11 20:02:00
【问题描述】:

我们正在尝试添加一个 locust grpc 客户端并从示例目录 here 获取代码。

我们的用例是 locust 将用作库而不是通过 UI。

我们在 csv 文件或代码中看到的统计信息输出的问题。我在 locust doc here 中看到的代码和我们的代码之间的唯一区别是服务是独立启动的。

此问题已在此 GitHub 存储库中重现:https://github.com/saurabhsharma721/grpc_locust_stats_repro_prj

此问题仅在库模式下观察到。如果我们通过 ui 运行它,则生成的统计信息是正确的。请帮忙。

【问题讨论】:

标签: python grpc performance-testing load-testing locust


【解决方案1】:

我不确定,但你试过添加这个吗?

# start a greenlet that save current stats to history
gevent.spawn(stats_history, env.runner)

(来自文档https://docs.locust.io/en/stable/use-as-lib.html

【讨论】:

  • 这样做但没有帮助
  • 嗯,好的。您能否验证在作为库运行时是否确实发出了请求? (在任务或其他东西中添加打印语句)。除此之外,我没有想法......
  • 任务正在运行,因为日志会打印出响应。试图挖掘为什么 ui 与非 ui 不同
【解决方案2】:

我可以使用以下代码解决这个问题:

添加了两个静态方法在初始化和拆除时调用

 @staticmethod
    def on_init(environment, **kwargs) -> None:  # type: ignore[no-untyped-def]
        print("Perform global setup to create a global state in LocustRunner")

 @staticmethod
    def on_quit(environment, **kwargs) -> None:  # type: ignore[no-untyped-def]
        print('Perform global teardown to clear the global state in LocustRunner')

然后在驱动中添加这段代码

events.init.add_listener(LocustRunner.on_init)
env = Environment(user_classes=[TestClass], events=events)
# Using local runner in start
runner = env.create_local_runner()
# init event
env.events.init.fire(environment=env, runner=runner)
Driver code 
# quit event
env.events.quitting.fire(environment=env, reverse=True)

已经有一个堆栈溢出答案,但目前无法搜索

【讨论】:

    猜你喜欢
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 2016-07-05
    • 2017-05-25
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    相关资源
    最近更新 更多