dimanche 8 mars 2015

Keeping objects alive through requests in Rails

In my web app, I have written simple card and dice multiplayer games. To keep the server game objects alive I use class references and set nginx to only use 1 passenger instance.



class Game
@@games ={game_1: Game.new, ...}
end


It is a low traffic site and seems to work well. The problem is that in another part of the app I added video uploading and transcoding via paperclip. With 1 passenger instance this is painfully slow, the transcoding takes about 10 times as long as it does without the passenger instance restriction.


I have the nginx worker_connections set to 1024 and it will never see even 30 concurrent connections. Are all connections going to be in the same passenger instance?


What is a good way to handle both cases? I can think of two approaches.


Move the games into their own standalone process(perhaps using event machine) and just use sockets to connect the rails app to it.


Fork the video processing and quickly return from the controller action and use something like faye to send success/fail messages.


Is there a better way to handle this?


Aucun commentaire:

Enregistrer un commentaire