首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当使用Locust对对接程序进行性能测试时,连接拒绝错误(111)

当使用Locust对对接程序进行性能测试时,连接拒绝错误(111)
EN

Stack Overflow用户
提问于 2020-03-05 16:36:35
回答 1查看 2.2K关注 0票数 2

我正在使用Locust,一种性能测试工具,来加载一个应用程序,该应用程序是在docker-组合中运行的。对于每个请求,我都会得到以下错误(连接被拒绝,错误111):

代码语言:javascript
运行
复制
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\',))",),)'

我从一个码头集装箱运行蝗虫,如下所示:

代码语言:javascript
运行
复制
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时,它会正常工作。

代码语言:javascript
运行
复制
curl http://localhost:8080/parties

任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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文件配置将工作:

代码语言:javascript
运行
复制
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组合的示例:

代码语言:javascript
运行
复制
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标志是关键!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60550111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档