Domanda

I have a JRuby 1.6.7/Rails 3.2.11 web application deployed on Glassfish (with no web server in front of it). I would like to make my application multi-threaded.

A best practices article suggests that I need to set the max and min runtimes to 1, and then go to config/environment.rb and put in the line

config.threadsafe!

However, a note from Oracle says (along with this note at Github) that I only have to set the minimum and maximum number of runtimes in the web.xml configuration file or the command line, and it says nothing about config.threadsafe!. (My feeling with this method is that it will take up a lot of memory because each runtime loads up a full instance of Rails).

Which method is right? Are they both right? Which is the better way to go multi-threaded?

È stato utile?

Soluzione

One must do the following

  1. set the min and max runtimes to 1
  2. go into config/environments/production.rb and uncomment the
    #config.threadsafe! line, you must also do this for any other environments you would want threadsafe mode to work in.

By doing these things Rails will run using one runtime and multiple threads saving you lots of memory. Additional information regarding threadsafe jruby on rails apps can be found here http://nowhereman.github.com/how-to/rails_thread_safe/

If you are using Warbler, you can skip step one - if you only follow step#2 the min and max runtimes will be set by default look at the web.xml within the war file you will see that it has been set. Likewise, if threadsafe has not been set you will see the absence of the min and max settings.

That being said Rails 4 will have threadsafe enabled by default. Here's the commit https://github.com/rails/rails/pull/6685

Also, here's a post about the hows and whys: http://tenderlovemaking.com/2012/06/18/removing-config-threadsafe.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top