Rails 本地主机上的应用程序 运行,但每当我检查网络浏览器时,我都拒绝连接

Rails app running on locahost, but I get connection refused whenever I check the web browser

我有一个 rails 应用程序,我已经 运行 在端口 3000 上连接了数周而没有任何事故,但我突然发现连接被拒绝了。

当我启动 rails 服务器时,我在控制台上得到以下输出:

=> Booting Puma
=> Rails 6.1.4.1 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.5.2 (ruby 3.0.2-p107) ("Zawgyi")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 717
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000

我的问题是在我 运行 JMeter 学习负载测试后开始的(我能够 运行 2 次测试,但后来它坏了)。我的 rails 应用程序 运行 在 Windows 10 (wsl 2) 的 linux 子系统上运行,我使用了 Apache JMeter 5.4.2。

我还测试了一个 NodeJs 应用程序,尝试使用其他端口(例如 8080),但仍然连接被拒绝。

我向 http://localhost:3000/ 发出了一个 curl 请求,它工作得很好,同样的 url 在任何网络浏览器上仍然让我连接被拒绝。

我找出问题所在并解决了它。事实证明,如果我 运行 在 windows 上运行 node js 应用程序,它工作得很好,所以所有迹象都表明问题实际上是在 wsl2.

我找到了一篇非常有用的文章 https://appuals.com/localhost-refused-to-connect/ 指导了我,我需要做的就是重新启动 LxssManager。

代表提问者发表

看起来问题与 WSL 有关

通常 运行 不建议在同一物理(或虚拟)机器上使用 JMeter(或任何其他工具),因为您可能会遇到 race condition when JMeter and your application under test will be struggling for the operating system resources hence results will be not very reliable as it will be hard to say where exactly is the bottleneck. Of course you can use i.e. JMeter PerfMon plugin 检查每个进程资源使用情况的问题,但它也可能无法讲述完整的故事。

另一个潜在的问题是 load testing in scaled-down environments may be an issue itself,您应该在类生产环境中进行 运行 性能测试。如果您有 4 GB 的 RAM 并且看到应用程序可以处理 1000 个用户,这并不意味着 8 GB 的 RAM 可以处理 2000 个用户,指标和 KPI 不能像这样推断。

最后但最不重要的一点是,您 运行 您的应用程序处于“开发”模式,我建议在 "production" mode instead

中执行它