Having a Multithreaded environment in JRuby after

2019-09-10 04:30发布

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.

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.

Is it reasonable to try it under JRuby and what containter is prefereable?

The host system is Ubuntu 14.04 x86_64.

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-10 04:59

OMG

I've included gem 'puma' http://puma.io/ and used Nginx proxy and it works!! This solution looks easier than JRuby, I think.

Previously I used Passenger and had similar surprises.

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.

查看更多
登录 后发表回答