连接未建立后在JRuby中具有多线程环境 [英] Having a Multithreaded environment in JRuby after ConnectionNotEstablished
问题描述
我有Rails(4.2.6)应用程序,在其中我使用了由Rufus :: Scheduler引起的线程进行后台数据处理.我在开发环境中有可用的应用程序,但是当我将其移至Nginx +载机上进行生产时,即使没有足够的负载,也会出现 ActiveRecord :: ConnectionNotEstablished 异常.
I have Rails (4.2.6) App where I use Thread(s) for background data processing caused by the Rufus::Scheduler. I have the working app in the development env, but when I move it to production on nginx + passenger I get exceptions ActiveRecord::ConnectionNotEstablished, even without sufficient load.
从线程执行的对ActiveRecord :: Base的所有后代的所有调用都包装在
All calls for ActiveRecord::Base's descendants that performing from Threads - are wrapped into
ActiveRecord::Base.connection_pool.with_connection{}
我以前从未使用过多线程环境,但是在对问题进行了调查之后,我建议可能是问题所在.
I've never used multi threaded environments before, but after some surveying of the problem, I suggest that probably this is the matter.
在JRuby下尝试使用它是否合理,并且首选哪种容器?
Is it reasonable to try it under JRuby and what containter is prefereable?
主机系统是Ubuntu 14.04 x86_64.
The host system is Ubuntu 14.04 x86_64.
推荐答案
OMG
我添加了gem'puma' http://puma.io/并使用了Nginx代理,它可以正常工作!!我认为,该解决方案看起来比JRuby容易.
I've included gem 'puma' http://puma.io/ and used Nginx proxy and it works!! This solution looks easier than JRuby, I think.
以前,我曾经使用过Vehicle,也有类似的惊喜.
Previously I used Passenger and had similar surprises.
首先,乘客进入空闲状态时会杀死线程.我已经在全球范围内启动了Thread和Rufus,而Passenger在开始2分钟后就将其杀死.
Firstly, Passenger kills thread when they become idle state. I have globally initiated Thread and Rufus, and Passenger was killing they after 2 minutes from start.
第二,这个问题,这是乘客出乎意料的.
Secondary, this issue and it was unexpected from Passenger.
好吧,问题已解决,该备忘录可能会对某人有所帮助.
Well, the issue is resolved and probably this memo could help somebody.
这篇关于连接未建立后在JRuby中具有多线程环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!