Say three Rails instances have been spawned and are taking requests.
For each request Thread.new is called a bunch of a times to put some cross cutting concerns out of band and return the response quicker.
What confuses me is what happens under the covers with the Rails instances.
I would guess that the Rails instance will not be ready to handle another request until all the threads spawned have finished executing?
To do this safely, you need to enable the threadsafe option in rails:
config.threadsafe!Otherwise, results will probably be undefined (depending on what operations you perform).
In either case, Rails will not block on the threads before handling another request. For this to happen, you would have to call
#joinon the threads. The threads will happily continue processing in the background. If you are after something more specific, please post some code.Note that normally a library such as
delayed_joborfactory_girlis used to provide background processing rather than instantiating threads yourself. See the documentation for the latter for a good argument on why you also use a ruby implementation with good threading support (I use JRuby) if you are doing this extensively.