Windows环境Locust高频HTTPS请求后异常停止问题求助
问题:Locust在Windows环境下运行约1分钟后停滞停止执行任务
问题现象
- 仅Windows系统出现该异常,相同Locust/Python版本、多Locust服务器配置的Linux环境无问题
- 单Locust服务器、5线程(含约100个基于FastHttpUser的HTTPS请求任务)场景会复现;简化为单任务单线程,向同子网服务器发起HTTPS请求仍可复现
- 改为HTTP请求、向公网服务器发起HTTPS请求或在请求间添加等待时间时,程序不会提前停止
- 停止时无报错信息,Locust服务器的CPU和内存状态正常
- 正常复杂测试场景下,约1分钟后停止,仅执行20-50次请求;升级Locust至2.15.1后问题依旧
调试信息
关键日志片段
[2023-05-31 10:05:18,545] Locust-01/INFO/locust.runners: All users spawned: {"TestTrafficLocust": 1} (1 total users) [2023-05-31 10:05:18,545] Locust-01/DEBUG/urllib3.connectionpool: Starting new HTTPS connection (1): test.localserver.com:443 [2023-05-31 10:05:20,248] Locust-01/DEBUG/urllib3.connectionpool: https://test.localserver.com:443 "GET /Check.asmx HTTP/1.1" 200 4409 [2023-05-31 10:05:20,248] Locust-01/DEBUG/urllib3.connectionpool: Starting new HTTPS connection (1): test.localserver.com:443 [2023-05-31 10:05:20,280] Locust-01/DEBUG/urllib3.connectionpool: https://test.localserver.com:443 "GET /Check.asmx HTTP/1.1" 200 4409 ... 443 repeated calls in 14 seconds ... [2023-05-31 10:05:34,014] Locust-01/DEBUG/urllib3.connectionpool: Starting new HTTPS connection (1): test.localserver.com:443 [2023-05-31 10:05:34,030] Locust-01/DEBUG/urllib3.connectionpool: https://test.localserver.com:443 "GET /Check.asmx HTTP/1.1" 200 4409 [2023-05-31 10:10:18,602] Locust-01/INFO/locust.runners: Shape test stopping [2023-05-31 10:10:18,602] Locust-01/DEBUG/locust.runners: Stopping all users
注:最后一次HTTPS请求与Locust关闭间隔超过4分钟
代码调试结果
测试代码片段:
print("This is printed") with client.get(f"https://test.localserver.com/Check.asmx", verify=False, catch_response=True, name="Test_HTTPS_Check") as healthResponse: if(healthResponse.status_code != 200): healthResponse.failure("This is never printed") return print("This is not printed")
- 执行到HTTPS请求步骤后停滞,
"This is not printed"从未输出 - Wireshark抓包未捕获到该请求,说明请求从未发起
- 调整
network_timeout和connection_timeout参数无效(因请求未发起),程序会一直等待至测试时长结束
环境配置
- locust:2.12.1(升级至2.15.1后问题依旧)
- Python:3.9.0
- Windows Server 2016 Standard 10.0.14393(VM)
- 内存:2.36 GB
- CPU:Xeon Silver 4116,6核
咨询问题
@task(1)能否设置超时?- 还有哪些方法可避免Locust停止?
- 在保证测试性能的前提下,添加任务间隔或增加线程是否可行?
内容的提问来源于stack exchange,提问作者Scott
相关产品推荐
相关产品推荐

