views:

128

answers:

1

I have a question regarding mod_passenger and Singleton classes (rails 2.3.5 and ruby 1.9.1).

In my aplication, I have a Singleton class that implements a thread pool (thread safe).

Also there is controller to manage all the threads (kill and start them). This controller uses the previous singleton class to do the actions over the threads.

In local, using WEBrick with config.cache_classes = true it works right. In production, using mod_passenger (also config.cache_classes = true), it doesn't work: the threads aren't killed. However, if I use the singleton class from a console (production environment), it works ok.

Could be the problem mod_passenger? Any tips?

Thanks.

A: 

This is caused because mod_passenger spawns multiple times the application, so the singleton class thread pool is not consistent between multiple controllers calls because every instance has his own thread pool.

I resolved the issue running the singleton class thread pool with a script/runner, and communicating it with all the applications instances using a database table. I use this table to send the jobs that the thread pool has to do.

fjyaniez