gpt4 book ai didi

ruby - 在开发模式下,Rails 应用程序的 Docker 容器运行速度非常慢

转载 作者:数据小太阳 更新时间:2023-10-29 07:37:17 27 4
gpt4 key购买 nike

我在 docker 容器上遇到了问题。 Rails 应用程序运行速度非常慢(意味着页面在浏览器上加载时间过长)。

申请详情:

Rails 版本:4.2.0 ruby 版本:2.2.0

当我通过命令 docker stats 检查内存状态时,显示主容器 (1) 的 CPU 使用率非常高。有时它会达到 50% 的利用率。

我尝试了一些配置,即增加 docker 的 CPU 分配,性能得到了一点提高。

version: '3.7'

services:
selenium:
image: selenium/standalone-chrome-debug:3.141.59-krypton
ports: ['4444:4444', '5900:5900']
logging:
driver: none
redis:
image: redis:3.0.0
elastic:
image: elasticsearch:1.5.2
db:
image: postgres:9.3.10
volumes:
- ./tmp/db:/var/lib/postgresql/data
- .:/home
XYZ:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
stdin_open: true
tty: true
volumes:
- .:/home
ports:
- "3000:3000"
depends_on:
- db
- redis
- elastic
- selenium
environment:
- REDIS_URL=redis://redis:6379/0
- ELASTICSEARCH_URL=elastic://elastic:9200/0
- SELENIUM_HOST=selenium
- SELENIUM_PORT=4444
- TEST_APP_HOST=XYZ
- TEST_PORT=3000

而且我观察到在浏览器上加载的 js 文件花费了太多时间来加载大约 1.3 分钟,例如,如果有 4 个 js 文件,每个文件花费的时间超过 1 分钟加载

我的感觉是 docker 在 mac 机器上运行缓慢,因为同样的应用程序在 Linux 机器上运行得很好,可能是我错了,但这是我看到的观察结果。

我们将不胜感激。

最佳答案

我通过设置 docker-sync 解决了我的问题。我按照这篇文章设置了 docker-sync

解决问题的步骤:

step1: sudo gem install docker-sync

step2:创建docker-sync.yml文件

version: "2"
options:
verbose: true
syncs:
#IMPORTANT: ensure this name is unique and does not match your other application container name
XYZ-sync: #tip: add -sync and you keep consistent names as a convention
src: .
sync_host_ip: 'localhost'
sync_host_port: 10872
sync_strategy: 'rsync'

第 3 步:使用以下详细信息更新 docker-compose.yml 文件

...
volumes:
- xyz-sync:/home:nocopy

volumes:
XYZ-sync:
external: true

step4: brew install rsync

step5: docker-sync-stack 开始

关于ruby - 在开发模式下,Rails 应用程序的 Docker 容器运行速度非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57709025/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com