Question

If I have the following action in a controller

def give_a
 print a
 a = a+1
end

What happens in each webserver when a request comes and when multiple requests are recieved?

I know that webrick and thin and single threaded so I guess that means that the a request doesn't get processed until the current request is done.

What happens in concurrent webservers such as puma or unicorn (perhaps others) If there are 2 requests coming and 2 unicorn threads handle them, would both responses give the same a value? (in a situation when both request enter the method in the same time)

or does it all depend on what happens on the server itself and the access to data is serial?

Is there a way to have a mutex/semaphore for the concurrent webservers?

Was it helpful?

Solution

afaik, the rails application makes a YourController.new with each request env.

from what you post, it is not possible to see, what a means. when it is some shared class variable, then it is mutuable state and could be modified from both request threads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top