2

我正在尝试创建一个蝗虫测试来对我的烧瓶应用程序进行负载测试

这是我的 locustfile.py

from locust import HttpLocust, TaskSet, task


class DataBaseTest(TaskSet):
    def on_start(self):
        pass

    @task(1)
    def get_home(self):
        self.client.get("/")


class WebsiteCassandra(HttpLocust):
    task_set = DataBaseTest
    min_wait = 5000
    max_wait = 9000

在端口 5000 中运行我的烧瓶网络应用程序

app.run("0.0.0.0", 5000)

在我的 locustfile.py 所在的目录中

locust --host=http://127.0.0.1:5000

当我运行测试时,出现以下故障

92  GET /   HTTPError(u'502 Server Error: Proxy Error ( Connection refused ) for url: http://127.0.0.1:5000/',)

手动请求 url 效果很好。但不是通过蝗虫。为什么你认为是这样?

4

1 回答 1

0

I was having a very similar problem, using the requests module, not locust. I think the cause might be the same though.

For me, the problem was my proxy configuration. I had the HTTP_PROXY environment variable set. So requests picked up that setting and dutifully made the request through my proxy.
This means my script's connection went from my machine to the proxy, then back to my machine. Because my machine's firewall doesn't have my development flask server's port open, the connection coming from the proxy was refused.

So, the short answer is to unset the http proxy in your script. It's as easy as:

import os
del os.environ['http_proxy']
于 2016-02-10T17:23:49.817 回答