Are Rails controllers multithreaded?
If so, can I protect a certain piece of code (which fires only once every ten minutes) from being run from multiple threads by
Ruby is single threaded. So at anytime, a controller can only handle one request at a time. If there are more than one requests, these requests are queued up. To avoid this, people usually run a small set of Mongrels to get good concurrency. It works like this(straight from Mongrel WIKI FAQ):
Mongrel then takes this StringIO output, any output headers, and streams them back to the client super fast.
Notice that if there is no locking if the page is cached.