views:

81

answers:

5

In ruby, if muliple HTTP request comes for single action/method then how ruby handles each and every request?

I don't know exactly, I heard that java uses multi thread concept. Is ruby uses the same or anything else? If it uses to create process for every request then this thing eat the cpu process.

+1  A: 

This is really a function of the web server you use, not the language. I would expect that it would use some combination of processes and/or threads within processes to handle each request. Look at your particular web server's documentation for more details.

tvanfosson
A: 

There are only one process to answer to this request. It's why you have a proxy system in front like 1 Nginx and 2 thin process behind. One request is handle by thin and return this result.

After there are system like EventMachine to improve CPU using. By example if you process wait some IO, EventMachine handle an other ruby thread during with waiting.

shingara
A: 

In Rails process takes care of only one request. If you have only one Rails process than all other requests would have to wait until first one is finished and so on.

Some time ago people were using Mongrel Cluster to have many Rails processes so each can handle one request at a time. Now I think that the most popular is Passenger - it can start dynamicaly more Rails processes is there is a need.

klew
if passenger runs more process than it may degrade the CPU Performance.what will happen if multiple request comes for same action at a time?
Arun
If you have only one process, then all requests will be processed sequentialy one after another - it will be quite slow. If you for example use passanger than it can start few Rails processes and each of them will handle one request in parallel - it will be much faster. Each Rails process will consume memory and CPU power. But this is how people are doing it. And it doesn't matter if all requests hit one action or different ones. It is handled in the same way.
klew
From this, can you distinguished the speed taken by java framework and rails?
Arun
I have no experience in Java at all. As a language it for sure is much faster than Ruby. When it comes to web development or frameworks (like RoR) many things depends on your design and implementation. You can create fast or slow service in both languages. I like Rails and Ruby and I wouldn't switch to C-like language in web development. I think that many things can be done much easier in Ruby and are much more readable. If you would smartly use caching than there wouldn't be noticable speed difference and Rails has many nice ways to introduce caching.
klew
BTW. what is your question about? You want to know about how Rails handles multiple requests, or what is better: Java or Ruby with RoR?
klew
A: 

Ruby itself is a single threaded programming language so it cannot take multiple request at the same time. But you can open multiple processes on your server to handle multiple request. When you want to know how it performs we need to calculate the throughput of the server. When you have very large number of request thats where people goes for cloud computing techniques like amazon.

A: 

I recommend reading http://yehudakatz.com/2010/08/14/threads-in-ruby-enough-already/, it explains most of it.

Tass