Locust 确实以 2xx 响应,但未能收集请求统计信息
Posted
技术标签:
【中文标题】Locust 确实以 2xx 响应,但未能收集请求统计信息【英文标题】:Locust does response with 2xx but fails to gather request statistics 【发布时间】:2020-05-06 15:56:51 【问题描述】:我正在尝试使用 Locust 进行本地负载测试。我启动并运行了测试环境,并且本地构建也在工作。我正在尝试测试本地路径的响应,并且我在终端中得到的响应是正确的。但是 Locust UI 以及终止测试后的统计数据给了我 100% 失败的结果。
为了创建蝗虫代码(我对它很陌生),我使用邮递员内容并对其进行了调整。这是蝗虫的代码:
from locust import HttpLocust, TaskSet, task, between
import requests
url = "http://localhost:8080/registry/downloadCounter"
payload = "[\n \n \"appName\": \"test-app\",\n \"appVersion\": \"1.6.0\"\n \n]"
class MyTaskSet(TaskSet):
@task(2)
def index(self):
self.client.get("")
headers =
'Content-Type': 'application/json',
'Accept':'application/json'
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
class MyLocust(HttpLocust):
task_set = MyTaskSet
wait_time = between(2.0, 4.0)
对于蝗虫群,我只使用了基本数字: 模拟用户总数:1 孵化率:3 主持人:http://localhost:8080/registry/downloadCounter
我在那里没有得到任何结果,表格保持空白。我想这与json格式有关,但我自己无法找到解决方案。
我还在这篇文章中放了一个终止后终端响应的屏幕截图。
提前感谢您的帮助!
最好的问候
【问题讨论】:
嗨,很抱歉推送。如果有人能帮我解决这个问题,那就太好了。 【参考方案1】:这有帮助:
from locust import HttpLocust, TaskSet, task, between
import requests
url = "http://localhost:8080/registry/downloadCounter"
payload = "[\n \n \"appName\": \"test-app\",\n \"appVersion\": \"1.6.0\"\n \n]"
headers = 'Content-type':'application/json', 'Accept':'application/json'
class MyTaskSet(TaskSet):
@task(2)
def index(self):
response = self.client.post(url = url, data = payload, headers=headers)
print(response.text.encode('utf8'))
print(response.status_code)
class MyLocust(HttpLocust):
task_set = MyTaskSet
wait_time = between(2.0, 4.0)
```
【讨论】:
以上是关于Locust 确实以 2xx 响应,但未能收集请求统计信息的主要内容,如果未能解决你的问题,请参考以下文章