gpt4 book ai didi

python - 如何将测试 api 的 Locust 结果写入文件

转载 作者:太空狗 更新时间:2023-10-29 22:07:41 26 4
gpt4 key购买 nike

我通过 API 调用测试,

locust -f locustfile.py --host=http://localhost --no-web  --hatch-rate=20 --clients=10000

得到结果

 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
POST 8000/queries.json 137 0(0.00%) 5 2 23 | 5 11.00

--------------------------------------------------------------------------------------------------------------------------------------------
Total 708 0(0.00%)

我想把这个结果写入一个文件。谁能帮我解决这个问题?

下面是python中的代码

@task(1)
def test_topview(self):
post_data_topview = """{ "category": "321", "num": 20, "genderCat" : ["23"] }"""
with self.client.request(method="POST", url="http://192.168.1.107:8001/queries.json", headers= {"Content-Type" : "application/json"}, data = post_data_topview, catch_response = True ) as response:
if not matched(response.content) :
response.failure("No content")

非常感谢。

最佳答案

更新

使用此选项保存 csv 文件 --csv 添加了此 release .因此,您可以运行以下命令将测试结果保存为 foo_requests.csvfoo_distribution.csv

locust -f locustfile.py --host=http://localhost --no-web  --hatch-rate=20 --clients=10000 --only-summary --csv=foo

适用于0.8以下版本

已经有保存 Locust 结果的提交,但还没有合并到 Locust。但是,您可以使用 this commit 手动更新它.它添加了一个新参数作为 --statsfile=result.log 来保存结果。

那么完整的命令应该是这样的

locust -f locustfile.py --host=http://localhost --no-web  --hatch-rate=20 --clients=10000 --only-summary --statsfile=result.log

可以查看this post用于更新 Locust 并检查日志结果。

关于python - 如何将测试 api 的 Locust 结果写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34704617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com