我正在使用Locust,一种性能测试工具,来加载一个应用程序,该应用程序是在docker-组合中运行的。对于每个请求,我都会得到以下错误(连接被拒绝,错误111):
Error report
# occurrences Error
--------------------------------------------------------------------------------------------------------------------------------------------
5 GET /parties/: 'ConnectionError(MaxRetryError("HTTPConnectionPool(host=\'localhost\', port=8080): Max retries exceeded with url: /parties/ (Caused by NewConnectionError(\'<urllib3.connection.HTTPConnection object at 0x7fa6f294df28>: Failed to establish a new connection: [Errno 111] Connection refused\',))",),)'我从一个码头集装箱运行蝗虫,如下所示:
docker run --volume /mydir/locustfile:/mnt/locust -e LOCUSTFILE_PATH=/mnt/locust/locustfile.py -e TARGET_URL=https://localhost:8080/parties -e LOCUST_OPTS="--clients=1 --no-web --run-time=600" locustio/locust奇怪的是,当我使用curl访问完全相同的URL时,它会正常工作。
curl http://localhost:8080/parties任何帮助都是非常感谢的!
发布于 2020-06-03 17:19:35
localhost可能是上下文中使用的错误主机名。使用容器时,主机名必须与容器的名称匹配。所以,使用容器的名称而不是localhost。
参考资料:
https://github.com/elastic/elasticsearch-py/issues/715
https://docs.locust.io/en/latest/running-locust-docker.html
https://docs.locust.io/en/stable/configuration.html
一般假设:
locustfile.py存在于当前工作目录中。
--一个带有docker组合的分布式示例:
例如,下面的docker-compose.yml文件配置将工作:
services:
web:
build: .
command: python manage.py runserver 0:8000
volumes:
- .:/code/
ports:
- "8000:8000"
master:
image: locustio/locust
ports:
- "8089:8089"
volumes:
- ./:/mnt/locust
command: -f /mnt/locust/locustfile.py --master -H http://web:8000
worker:
image: locustio/locust
volumes:
- ./:/mnt/locust
command: -f /mnt/locust/locustfile.py --worker --master-host master下面一行的-H标志(别名为--host)完成了这个任务:
command: -f /mnt/locust/locustfile.py --master -H http://web:8000
是一个非分布式的带有docker组合的示例:
services:
web:
build: .
command: python manage.py runserver 0:8000
volumes:
- .:/code/
ports:
- "8000:8000"
locust:
image: locustio/locust
ports:
- "8089:8089"
volumes:
- ./:/mnt/locust
command: -f /mnt/locust/locustfile.py --host=http://web:8000您还可以指定一个配置文件,而不是定义命令行上的标志。假设文件locust.conf存在于当前工作目录中:
locust.conf:
host: http://web:8000
所以在你的docker-compose.yml中你需要:
command: -f /mnt/locust/locustfile.py --config=/mnt/locust/locust.conf
而不是:
command: -f /mnt/locust/locustfile.py --host=http://web:8000
是一个非分布式的示例,没有docker组合:
容器必须生活在同一个网络上,这样它们才能相互通信。为此,让我们创建一个名为locustnw的公共桥接网络
docker network create --driver bridge locustnw
现在在这个网络中运行您的应用程序容器。假设它正在监听端口8000,并命名为web:
docker run -p 8000:8000 --network=locustnw --name web <my_image>
现在运行您的蝗虫容器,在同一网络中也。它正在监听8089端口:
docker run -p 8089:8089 --network=locustnw -v $PWD:/mnt/locust locustio/locust -f /mnt/locust/locustfile.py --host=http://web:8000
--network、--name和--host标志是关键!
https://stackoverflow.com/questions/60550111
复制相似问题