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?
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)
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.
© 2022 - 2024 — McMap. All rights reserved.