首页 > 解决方案 > Locust 负载测试给了我 ChunkedEncodingError

问题描述

我正在负载测试我的 django gunicorn nginx 和 postgresql 应用程序。在大约 1500 个并发用户之后,我的 locust failed 选项卡中出现以下错误:

1   GET /   ChunkedEncodingError(ProtocolError('Connection broken: IncompleteRead(2773 bytes read, 7467 more expected)', IncompleteRead(2773 bytes read, 7467 more expected)))

我检查了我所有的访问和错误日​​志(nginx 访问和错误日​​志、gunicorn 日志、syslog、postgresql 日志),但我找不到与上述错误相关的任何内容。

是蝗虫错误吗?是超时错误吗?我似乎找不到出了什么问题。

这是我的蝗虫文件:

from locust import HttpLocust, TaskSet, task, between
from requests.auth import HTTPBasicAuth


class UserBehavior(TaskSet):

    @task(4)
    def index(self):
        self.client.get("", auth=("user", "pass"))

    @task(4)
    def program(self):
        self.client.get("page1/", auth=("user", "pass"))

    @task(1)
    def artist(self):
        self.client.get("page1/sub-page/", auth=("user", "pass"))

    @task(2)
    def tickets(self):
        self.client.get("page2/", auth=("user", "pass"))


class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    wait_time = between(7, 30)

如您所见,我正在使用基本身份验证来访问该页面。我不知道在很多请求之后这是否真的会导致错误。

什么可能导致此错误?提前致谢!

标签: pythonpostgresqlnginxgunicornlocust

解决方案


有人(可能是服务器)似乎正在关闭连接,而 locust 并不能告诉你更多。

SO上有许多关于此异常的其他票证(关于一般的请求库,而不是专门针对蝗虫),也许其中一个可能会有所帮助。

您也可以尝试新的 FastHttpLocust,它使用不同的请求库(您很可能仍然会收到错误,但可能会显示不同的内容)

在服务器端检查您的 ulimits 设置可能是值得的。


推荐阅读