<p>Even though <a href="http://twistedmatrix.com/pipermail/twisted-python/2004-May/007896.html" rel="noreferrer">Python</a> and <a href="http://www.reddit.com/comments/6wmum/thread_safe_ruby_on_rails_in_22_release/" rel="noreferrer">Ruby</a> have one kernel thread per interpreter thread, they have a global interpreter lock (GIL) that is used to protect potentially shared data structures, so this inhibits multi-processor execution. Even though the portions in those languajes that are written in C or C++ can be free-threaded, that's not possible with pure interpreted code unless you use multiple processes. What's the best way to achieve this? <a href="http://blogs.codehaus.org/people/tirsen/archives/001041_ruby_on_rails_and_fastcgi_scaling_using_processes_instead_of_threads.html" rel="noreferrer">Using FastCGI</a>? Creating a <a href="http://blog.innerewut.de/files/images/stage_2.png" rel="noreferrer">cluster or a farm</a> of virtualized servers? Using their Java equivalents, JRuby and Jython?</p>

[{'answer_id': 37146, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 1, 'selected': False, 'text': "<p>Use an interface that runs each response in a separate interpreter, such as <code>mod_wsgi</code> for Python. This lets multi-threading be used without encountering the GIL.</p>\n\n<p>EDIT: Apparently, <code>mod_wsgi</code> no longer supports multiple interpreters per process because idiots couldn't figure out how to properly implement extension modules. It still supports running requests in separate processes FastCGI-style, though, so that's apparently the current accepted solution.</p>\n"}, {'answer_id': 37153, 'author': 'Peter Hoffmann', 'author_id': 720, 'author_profile': 'https://Stackoverflow.com/users/720', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m not totally sure which problem you want so solve, but if you deploy your python/django application via an apache prefork MPM using mod_python apache will start several worker processes for handling different requests.</p>\n\n<p>If one request needs so much resources, that you want to use multiple cores have a look at <a href="http://pyprocessing.berlios.de/" rel="nofollow noreferrer">pyprocessing</a>. But I don\'t think that would be wise.</p>\n'}, {'answer_id': 37203, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 2, 'selected': False, 'text': '<p>The \'standard\' way to do this with rails is to run a "pack" of Mongrel instances (ie: 4 copies of the rails application) and then use apache or nginx or some other piece of software to sit in front of them and act as a load balancer. </p>\n\n<p>This is probably how it\'s done with other ruby frameworks such as merb etc, but I haven\'t used those personally.</p>\n\n<p>The OS will take care of running each mongrel on it\'s own CPU.</p>\n\n<p>If you install <a href="http://www.modrails.com/" rel="nofollow noreferrer">mod_rails aka phusion passenger</a> it will start and stop multiple copies of the rails process for you as well, so it will end up spreading the load across multiple CPUs/cores in a similar way.</p>\n'}, {'answer_id': 190394, 'author': 'dmeister', 'author_id': 4194, 'author_profile': 'https://Stackoverflow.com/users/4194', 'pm_score': 1, 'selected': False, 'text': '<p>In Python and Ruby it is only possible to use multiple cores, is to spawn new (heavyweight) processes.\nThe Java counterparts inherit the possibilities of the Java platform. You could imply use Java threads. That is for example a reason why sometimes (often) Java Application Server like Glassfish are used for Ruby on Rails applications.</p>\n'}, {'answer_id': 191257, 'author': 'David Eyk', 'author_id': 18950, 'author_profile': 'https://Stackoverflow.com/users/18950', 'pm_score': 0, 'selected': False, 'text': '<p>For Python, the <a href="http://pyprocessing.berlios.de/" rel="nofollow noreferrer">PyProcessing</a> project allows you to program with processes much like you would use threads. It is included in the standard library of the recently released 2.6 version as <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow noreferrer"><code>multiprocessing</code></a>. The module has many features for establishing and controlling access to shared data structures (queues, pipes, etc.) and support for common idioms (i.e. managers and worker pools).</p>\n'}]
['https://Stackoverflow.com/questions/37142', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3855/']