Reputation: 4706
What does a Rails controller do when one of its line takes a very long time? For example, one of the line wants to sleep for a very long time, like 10000 seconds: sleep(10000)
. If many people use the website and calls this controller method, does it use up a huge amount of resources?
Upvotes: 1
Views: 458
Reputation: 10405
It will sleep for 10000
seconds, thus blocking one ruby process the whole time.
If your web server is set up to timeout before this delay, the browser will render an error message, but that won't stop the Rails process.
So no magic here.
It won't use resources while sleeping, but the RAM needed for the ruby process won't be freed. And since for each request to this action one process gets stuck, starting at max_nb_ruby_processes_on_your_server
request to this action in parrallel, your website will become unresponsive for every request, no more Ruby process available to handle requests.
If you have complicated data to process, it's usually best to handle it through a rake task
that you'll be calling asynchronously via crontab or delayed jobs
Upvotes: 1