【发布时间】: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