请求卡在ActiveRecord :: QueryCache中间件中 [英] Requests got stuck in ActiveRecord::QueryCache middleware
问题描述
在部署我们的Rails应用程序(4.0.9,Ruby 2.1.2)之后,我们注意到对我们的应用程序的请求在一段时间(通常为1天左右)后挂起.
After deploying our Rails app (4.0.9, Ruby 2.1.2), we notice requests to our app get hang after a while , usually 1 day or so.
使用宝石rack_timer
,我们可以找出停留在ActiveRecord :: QueryCache中间件上的请求.
Using the gem rack_timer
, we're able to find out requests got stuck at ActiveRecord::QueryCache middleware.
Rack Timer (incoming) -- ActiveRecord::QueryCache: 925626.7731189728 ms
将其删除后,我们的应用似乎恢复了正常.但是,我知道此中间件的目的是提高性能,因此删除只是一个临时解决方案.我们正在使用带有适配器mysql2
(0.3.13)
After removing it, our app seems to be back to normal. However, I understand the purpose of this middleware is to increase the performance, so removing is just a temporary solution. We're using mysql (5.1.67) with adapter mysql2
(0.3.13)
更新:在我发布此问题之后,服务器立即再次挂起,这次请求被卡在ActionDispatch :: Routing :: RouteSet
Update: Right after I posted this question, the server started hang again, this time requests were stuck at ActionDispatch::Routing::RouteSet
I, [2014-10-13T23:17:03.661346 #32498] INFO -- : Rack Timer (Application Action) -- ActionDispatch::Routing::RouteSet: 3667661.2360477448 ms
I, [2014-10-13T23:17:03.661946 #32498] INFO -- : Rack Timer (Application Action) -- ActionDispatch::Routing::RouteSet: 4373914.719343185 ms
您知道什么原因会导致这种情况吗?
Do you know any reason could cause this?
谢谢.
推荐答案
最可能的原因是您与数据库的连接中断(防火墙,服务器配置...),并且Rails没注意到,所以在ActiveRecord::QueryCache
.一旦Rails注意到连接中断,它就会重新连接并且执行流程继续.
The most possible cause is your connection with the database died (firewall, server configuration...) and Rails didn't notice, so a timeout happens inside ActiveRecord::QueryCache
. Once Rails notices the connection died, it reconnects and the execution flow continues.
尝试将database.yml
文件中的参数read_timeout
设置为10秒左右,然后检查连接和服务器设置.
Try setting the param read_timeout
in your database.yml
file to something like 10 seconds and check your connection and server settings.
这篇关于请求卡在ActiveRecord :: QueryCache中间件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!