I am trying to understand how each web request works in rails application. To understand my logic I have written this dummy controller.
class TestsController < ApplicationController
def index
puts 'Going to Sleep'
sleep 30.seconds
render json: { message: 'ok' }
end
end
I use puma as my application server. I ran rails server in production mode and visited locahost:3000/tests in 5 different tabs in browser. My understanding was since puma is concurrent server, each request will run under different thread, that's why request blocked by first request won't block request for second request because that request will be handled by seperate thread.
But when I look into server log in terminal I see message Going to Sleep appear on first request and then ruby goes to sleep for 30 second. For second request and other requests I don't see message Going to Sleep in log file for 30 seconds (until first request have finished sleeping). This is confusing me a-lot, I thought for each 5 requests on different tabs on browser I will see message Going to Sleep immediately and non of request will block each other. But looks like I am wrong.
Can some one please explain it to me how it works ? My first request is blocking other request. Isn't that problem? In real world application if I make api call to 3rd party application and if it takes longer to get response back than it will block request for other users ? Or do I need to make http request from different ip addresses for concurrency to work? Please explain.
UPDATA
Below is my puma configuration
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count