Do multiple requests in Phusion passenger run in their own threads?
Asked Answered
S

2

7

I have a Ruby on Rails application deployed with Phusion passenger + Apache web server. Does each request runs in its own thread spawned by Phusion Passenger?

Sudbury answered 6/9, 2013 at 1:15 Comment(0)
E
7

Passenger (along with most other application servers) runs no more than one request per thread. Typically there is also only one thread per process. From the Phusion Passenger docs:

Phusion Passenger supports two concurrency models:

  • process: single-threaded, multi-processed I/O concurrency. Each application process only has a single thread and can only handle 1 request at a time. This is the concurrency model that Ruby applications traditionally used. It has excellent compatibility (can work with applications that are not designed to be thread-safe) but is unsuitable workloads in which the application has to wait for a lot of external I/O (e.g. HTTP API calls), and uses more memory because each process has a large memory overhead.

  • thread: multi-threaded, multi-processed I/O concurrency. Each application process has multiple threads (customizable via PassengerThreadCount). This model provides much better I/O concurrency and uses less memory because threads share memory with each other within the same process. However, using this model may cause compatibility problems if the application is not designed to be thread-safe.

(Emphasis my own)

Edh answered 6/9, 2013 at 2:23 Comment(2)
Is the process concurrency model used in Phusion Passenger free edition?Sudbury
Yes, Phusion Passenger does more than one thread per request. It creates one process per request, if it is allowed to, until max amount of processes is reached. Then it begins to add threads to existing processes. Free version always creates multiple processes and this makes a great headache for me as I have a global object which should be unique in a whole application, but I am getting one instance per process (but this is not a problem for classical RoR apps as they should not have such objects). The paid Enterprise version ($30/month) claims to be able to limit processes to 1 per app.Insufficiency
W
0

Passenger open source edition only uses one thread per application, as listed in your apache virtual hosts files (not sure about nginx). So you could conceivably have multiple instances of your app running on the same apache server, but you would have to install your app into multiple directories and point vhosts entries at them, and put some kind of load-balancer in front of it. Passenger enterprise enables much more control over concurrency.

EDIT: clarity.

Whereon answered 21/3, 2014 at 0:11 Comment(1)
This is incorrect. The number of threads in Apache are completely independent from Phusion Passenger, and thus whether you are using open source or Enterprise has got absolutely nothing to do with it. The number of threads are solely determined by the Apache MPM settings such as ThreadsPerChild. What the Enterprise version does offer, is running the app itself (not Apache, not Nginx) with multiple threads.Canaanite

© 2022 - 2024 — McMap. All rights reserved.