Rails 用 docker 搭建的 rails 开发环境,宿主机访问网页特别慢

ytp · 2023年07月24日 · 最后由 ytp 回复于 2023年07月28日 · 627 次阅读

我是用 win 系统安装的 docker,再在 docker 上搭建了 rails 开发环境。如上图,本地访问个文章列表花了我 4s 多,有什么好的方法优化一下吗?

检查下 是不是 rails6 之后没单独运行 webpacker?

jicheng1014 回复

用的 rails 7,没有 webpacker 了

诶 那倒是挺奇怪的 可以上 newrelic 分析一下

贴日志。

Rei 回复
Started GET "/articles" for 172.20.0.1 at 2023-07-25 09:34:33 +0000
Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by ArticlesController#index as HTML
  Rendering layout layouts/application.html.erb
  Rendering articles/index.html.erb within layouts/application
  [1m[36mArticle Load (0.4ms)[0m  [1m[34mSELECT "articles".* FROM "articles"[0m
  ↳ app/views/articles/index.html.erb:10
  Rendered articles/index.html.erb within layouts/application (Duration: 3.5ms | Allocations: 742)
  Rendered layout layouts/application.html.erb (Duration: 5.4ms | Allocations: 1492)
Completed 200 OK in 3646ms (Views: 6.1ms | ActiveRecord: 0.4ms | Allocations: 1846)


Started GET "/articles" for 172.20.0.1 at 2023-07-25 09:34:54 +0000
Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by ArticlesController#index as HTML
  Rendering layout layouts/application.html.erb
  Rendering articles/index.html.erb within layouts/application
  [1m[36mArticle Load (0.4ms)[0m  [1m[34mSELECT "articles".* FROM "articles"[0m
  ↳ app/views/articles/index.html.erb:10
  Rendered articles/index.html.erb within layouts/application (Duration: 3.1ms | Allocations: 742)
  Rendered layout layouts/application.html.erb (Duration: 5.1ms | Allocations: 1480)
Completed 200 OK in 3899ms (Views: 6.0ms | ActiveRecord: 0.4ms | Allocations: 1851)


Started GET "/articles" for 172.20.0.1 at 2023-07-25 09:35:04 +0000
Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by ArticlesController#index as HTML
  Rendering layout layouts/application.html.erb
  Rendering articles/index.html.erb within layouts/application
  [1m[36mArticle Load (0.4ms)[0m  [1m[34mSELECT "articles".* FROM "articles"[0m
  ↳ app/views/articles/index.html.erb:10
  Rendered articles/index.html.erb within layouts/application (Duration: 3.1ms | Allocations: 742)
  Rendered layout layouts/application.html.erb (Duration: 5.1ms | Allocations: 1477)
Completed 200 OK in 3748ms (Views: 6.0ms | ActiveRecord: 0.4ms | Allocations: 1832)

感觉和文件系统有关,在 mac docker 下都是秒回,win docker 测试了几遍拉文章列表,都要 3 秒多了

类似的问题我在 windows 的 wsl2 中遇到过,当项目文件放在 windows 的文件系统上时,响应会特别慢,把项目文件放在 wsl2 里后,速度就正常了

spike76 回复

好的哦,应该是这个问题,我今天下班了回去试试

就是 win docker 的问题,我 100 毫秒响应的页面,win 的 docker 跑到 30 秒,我都惊呆了。

我都见过有公司在 win 跑虚拟机,在 linux 虚拟机里再跑 docker,速度比 win 直接运行 docker 快很多很多。

spike76 回复

我试了把项目文件放在 wsl2 里后感觉变化不大,是不是操作错了😂

canonpd 回复

应该要这样,我打算以后都用 mac 学习 ruby 了

ytp 关闭了讨论。 08月02日 13:17
需要 登录 后方可回复, 如果你还没有账号请 注册新账号