【问题标题】:Locust seeming to fire request_success event hook 60x than my actual requestsLocust 似乎触发 request_success 事件挂钩 60 倍于我的实际请求
【发布时间】:2020-01-08 01:19:03
【问题描述】:

我正在使用 Locust 进行一些负载测试。值得一提的是,我还在使用 Graphite 和 Grafana 来分析结果,但我可以在不加载或在我的代码中使用其中任何一个的情况下产生这个问题。

在最简单的情况下,可以使用以下非常简单的 locust 文件重现该问题:

from locust import HttpLocust, TaskSet, task, between
import locust.events


class Tasks(TaskSet):
    @task
    def make_request(self):
        self.client.get('/')
        print('doing thing')


class Locust(HttpLocust):
    wait_time = between(1, 3)
    task_set = Tasks

    def __init__(self):
        super(Locust, self).__init__()
        locust.events.request_success += self.hook_request_success

    def hook_request_success(self, request_type, name,
                             response_time, response_length):
        # This is where I would make a call to send the request's metadata to Graphite
        print("sending thing")

这样称呼:

locust -H <host> -t 10s -c 1000 -r 10 --no-web -f test.py

如您所见,规范是基本的。我有一个单任务计划,我想执行一个请求,将每个请求的结果发送到 Graphite。但是,在我所有运行的标准输出中,当我假设它们恰好是一对一时,我得到的“发送事物”实例比“做事物”的实例多近六十 (60) 倍!我已经确认该函数是使用相同的参数调用的,并且代表完全相同的请求,只是为蝗虫发出的每个“实际”请求调用了无数次。我根本不想要这个,我只想发送一次请求。

这是为什么?是不是我做错了什么?

【问题讨论】:

    标签: python performance-testing locust


    【解决方案1】:

    每次生成/实例化蝗虫时,您都会添加事件侦听器。

    使 hook_request_success 成为一个全局函数并从那里添加它,将其更改为如下内容:

    locust.events.request_success += hook_request_success
    

    这样它只会被添加一次,这就是你想要的。

    【讨论】:

    • 完全成功! Cyber​​wiz 确实如此。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 2018-01-10
    • 1970-01-01
    • 2013-05-06
    • 2013-07-28
    • 2015-06-25
    • 1970-01-01
    相关资源
    最近更新 更多