We are trying to deploy mongrel instances on a machine. What is the optimal number of mongrel instances for a server? Since an instance can handle concurrent connections, I do not see any benefit in starting more than 1 per core. Any more than that and the threads will just fight for CPU. Our predecessors have assigned 10 instances for 4 cores, but I think it will just cause CPU contention. Any definitive answers / opinions?

I have seen this question: How many mongrel instances?

But it is really not specific enough.

  • Is there a particular reason you want to use mongrel as opposed to Phusion Passenger? – bwizzy Jan 12 '11 at 1:08
  • Thank you for the question, just because it is already in production and we are trying to allocate thin instances for a new server and Phusion is on our roadmap, but we cannot do immediately. Actually we are using Thin. I was reading that Thin uses Eventmachine so does not block on IO. – Amala Jan 12 '11 at 20:37

A coworker emailed the author of thin who confirmed 1 thin instance per core. Gets more interesting for hyperthreaded cores, but that is probably another question.

Colleagues have said that mongrel blocks on IO. Thin uses eventmachine to not block on IO and uses Mongrel as the HTTP library.

  • BTW This is all only really relevant for Rails after 2.2, before that an app instance was really single threaded and could only take one request at at time. – Amala Jan 26 '11 at 16:20

Mongrel instances may handle concurrent connections, but are you sure that all codepaths will never block? I recall that some gems still exist which block, which could cause you trouble.

Instead of looking for hard rules, I defer to measurements in these kind of situations. Design a test which offers a reasonable approximation of expected traffic and compare different configurations.

  • OK thanks, I found some resources which say that with versions of Rails from 2.2 Rails threadsafe and will not block. But we are running 2.1.1. So far I have not seen blocking directly on IO waits like DB calls. I only see it blocking in production when the CPU is busy. – Amala Jan 12 '11 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.