Python蝗虫 - req/task中的自定义超时

发布于 2025-01-25 02:08:05 字数 499 浏览 3 评论 0原文

我需要使用Locust Lib进行一些负载测试。我要以特定方式处理504-Gateway超时。是否有可能在请求(或任务)中放置自定义超时。我不需要等待120秒直到超时,我需要等待不超过5秒,对我来说是超时。 我的意思是在代码中:

@task(1)
def check_max_5_sec(self):
   self.client.get(url=URL_5_sec)

...

@task(1)
def check_max_10_sec(self):
   self.client.get(url=URL_10_sec)

在理想的世界中,如果给定超时内没有响应,我希望在蝗虫Web界面上看到故障。 如何实现这一目标?

我知道在fasthttp中有Connection_timeoutnetwork_timeout(可能这可能是解决方案),但是我可以使用httpuser做到这一点

I need to run some Load tests with Locust lib. I neeed to to handle 504-gateway timeout in specific way. Is there a possibility to put custom timeout in request (or maybe task). I do not need to wait 120 sec till timeout occurs, I need to wait not wait longer than 5 sec and for me it is timeout.
I mean in code:

@task(1)
def check_max_5_sec(self):
   self.client.get(url=URL_5_sec)

...

@task(1)
def check_max_10_sec(self):
   self.client.get(url=URL_10_sec)

In ideal world I'd like to see failures on Locust web interface if there is no response within given timeout.
How to achieve this?

I know that in FastHttp there is connection_timeout and network_timeout (probably this might be a solution), but can I do this with HttpUser?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2025-02-01 02:08:05

对于httpuser/请求,只需通过timeout = 5即可。

参见 https://docs.pys.python-requests.orgg/en/最新/用户/QuickStart/#超时有关更多信息。

For HttpUser/requests just pass timeout=5.

See https://docs.python-requests.org/en/latest/user/quickstart/#timeouts for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文