为什么 Rails 不能与 mod_ruby 一起使用?
如果这听起来像是一个愚蠢的问题,我很抱歉,因为这似乎是那些“不废话”的事情之一,但是有人可以向我解释一下为什么 Rails 需要自己的服务器(Mongrel、WEBrick、mod_rails 等)并且可以'不只是使用 mod_ruby 吗?
I'm sorry if this sounds like a stupid question, because it seems to be one of those "no duh" things, but can someone explain to me why Rails needs its own server (Mongrel, WEBrick, mod_rails, etc) and can't simply use mod_ruby?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所有运行 mod_ruby 的 apache 实例共享一个 Ruby 解释器。 这意味着它根本不能在共享主机上或每台机器上运行多个 Rails 应用程序的任何环境中使用。 可能可以在一台计算机上运行同一应用程序的多个副本,但您也可能很容易遇到难以追踪的错误。 因为 Rails 是单线程的,所以每台机器只运行一个 ruby 进程是不可想象的。
而且,它的表现也不是那么好。
如需更深入的讨论,请查看 该 Phusion 员工的博客
All apache instances running mod_ruby share a Ruby interpreter. This means that it can't be used at all on shared hosts, or in any environment where there are multiple Rails applications running per machine. In might be possible to run multiple copies of the same application on one machine but you could also easily experience difficult to track down bugs. Because rails is single threaded, running only one ruby process per machine is sort of unthinkable.
Also, it doesn't perform all that well.
For a more in depth discussion, check out this Phusion employee's blog
已经有人回答说 mod_ruby 会产生共享的 Ruby 解释器,但是这特别有问题的原因是它意味着类会互相践踏。 例如,考虑 ActiveRecord::Base 它定义了到某个数据库的连接。 不同的 Rails 应用程序之间这个类的状态是不同的,因此一旦多个 Rails 应用程序在同一个解释器上运行,就会出现严重的类冲突。
另一个答案指出 Rails 是单线程的,但从 Rails 2.2.2 开始这不一定是真的。 我会留下这个作为对该答案的评论,但我穿着业力紧身衣:)
It has already been answered that mod_ruby results in a shared Ruby interpreter but the reason this is particularly problematic is that it means classes trample over each other. For example, consider ActiveRecord::Base which defines a connection to a certain database. The state of this class is different between different Rails applications, so as soon as more than one Rails application were to be run on the same interpreter, you have serious class warfare.
Another answer stated that Rails is single threaded, but this is not necessarily true as of Rails 2.2.2. I'd leave this as a comment on that answer but I'm in a karma straitjacket :)
“mod_ruby 对每个 Apache 进程使用一个解释器,这意味着应用程序
在命名空间中互相行走。 至少对于 Rails 来说是这样
不可接受,因此如果您需要 mod_ruby,则每个 Apache 设置需要 1 个应用程序。” - David Heinemeier Hansson
现在它已经被一些人嘲笑了,如果你仍然想使用它,请查看 mod_ruby 常见问题解答
Dreamhost 确实尝试将 ruby 纳入他们的托管环境,这是从他们的博客中得出的结论。
"mod_ruby uses one interpreter per Apache process, which means that apps
walk all over each other in the namespaces. At least for Rails, that's
not acceptable, so it's 1 app per Apache setup if you want mod_ruby." - David Heinemeier Hansson
Now that it's been derided some, if you still want to use it, check out the mod_ruby FAQ
Dreamhost did try to include ruby into their hosting environment, this from their blog on their conclusions from this endeavor.