防止 Mongrel/Mysql Errno::EPIPE 异常
我有一个 Rails 应用程序,我很少提供 XML。 这是使用 mongrel 和 mysql 运行的。 我发现,如果我不使用该应用程序超过几个小时,它就会死机并开始抛出 Errno::EPIPE 错误。 mysql 连接似乎因不活动或类似原因而超时。
它可以用“mongrel_rails restart -P /path/to/the/mongrel.pid”重新启动...但这并不是真正的解决方案。 我的合作者希望当他工作时该应用程序就在那里(而我很可能不在身边)。
我的问题是:
- 我能做些什么来防止这个问题发生? (例如,不要让我超时!!)。
- 如果失败,是否可以在某处插入一些代码来自动重新建立数据库连接?
I have a rails app that I have serving up XML on an infrequent basis.
This is being run with mongrel and mysql.
I've found that if I don't exercise the app for longer than a few hours it goes dead and starts throwing Errno::EPIPE errors. It seems that the mysql connection get timed out for inactivity or something like that.
It can be restarted with 'mongrel_rails restart -P /path/to/the/mongrel.pid' ... but that's not really a solution.
My collaborator expects the app to be there when he is working on his part (and I am most likely not around).
My question is:
- What can I do to prevent this problem from occurring in the 1st place? (e.g. don't time me out!!).
- Failing that, is there some code I can insert somewhere to automatically remake the Db connection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个解决方案:
https://boxpanel.blueboxgrp.com/public/ the_vault/index.php/Mongrel_/_MySQL_Timeout
上述解决方案的超时对我来说似乎有点高。 由于连接可以使用的内存量,您不希望数据库超时太低。 如果某个连接是孤立的,您希望它合理地超时(比如不要在一周内超时)。
Here's a solution:
https://boxpanel.blueboxgrp.com/public/the_vault/index.php/Mongrel_/_MySQL_Timeout
The timeouts on the above solution seem a little high to me. You don't want your DB timeouts to be too low, because of the amount of memory a connection can use. If a connection is orphaned, you want it to time out reasonably (like not in one week.)
在其他地方,我也得到了以下建议:
尝试设置
config.active_record.verification_timeout 低于任何值
你的mysql连接超时设置是。
有一个 gem 可以解决这个问题:mysql_retry_lost_connection
<预><代码> http://rubyforge.org/projects/zventstools/
“当您遇到丢失连接错误时重新连接到 MySQL 服务器”。
In other places, I also got the following suggestions:
Try setting
config.active_record.verification_timeout to something lower than whatever
your mysql connection timeout setting is.
There's a gem to work around this problem: mysql_retry_lost_connection