Rails 3.1 线程安全被破坏
或者类似的东西。我已将多个应用程序从 Rails 3.0 升级到 Rails 3.1。它们在启用多线程选项的 Thin 上运行,它们都配置了线程安全!。在 Rails 3.0 中工作得很好。但在 3.1 中,经过几次请求后,速度开始变慢。经过几次请求后,页面挂起 N 秒(其中 N 是我的数据库超时),并且我收到此错误:
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it.):
过去已经找到了 5 和 5 的默认值,并且应该仍然没问题。增加它们并不能解决问题,尽管需要更长的时间才能显现出来。我应该强调,在这些时间里,我是唯一访问这些应用程序的人。当我将 Thin 降为单线程模式时,一切都按预期工作。
MySQL、SQLite、Ruby 1.8.7 和 Ruby 1.9.2 会出现这种情况。薄不变。我能找到的唯一变量是升级到 Rails 3.1。我能做些什么吗,或者这是 Rails 中的回归?
Or something like that. I've upgraded several apps from Rails 3.0 to Rails 3.1. They are are running on Thin with the multithreaded option enabled, they are all configured with threadsafe!. Worked great in Rails 3.0. But in 3.1, after a few requests, things start slowing down. After a few more requests, the pages hangs for N seconds (where N is my db timeout) and I get this error:
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it.):
Those default values of 5 and 5 have been find in the past and should still be fine. Also increasing them does not fix the problem, though it takes a little longer to manifest. I should stress that during these times I have been the only one accessing the apps. When I drop Thin down to single-threaded mode, everything works as expected.
This occurs with MySQL, SQLite, Ruby 1.8.7 and Ruby 1.9.2. Thin is unchanged. The only variable I can find is the upgrade to Rails 3.1. Is there anything I can do, or is this a regression in Rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这是一个错误。有一个补丁和拉取请求。希望 Rails 能够将其合并进来。在那之前,多线程 Rails 应用程序将无法在 Thin 上运行。
https://github.com/rails/rails/pull/1670
Looks like this is a bug. There's a patch and pull request for it. Hopefully Rails will merge it in. Until then, multi-threaded Rails apps won't work on Thin.
https://github.com/rails/rails/pull/1670