ruby-on-rails – Rails:乘客一次不能处理多个请求

我已经读过乘客是一个多进程服务器,这意味着它可以一次处理多个请求.

我在本地机器上以独立模式运行乘客并编写代码以检查乘客是否能够同时运行多个请求.我的代码是:

class Test < ApplicationController

 def index
   sleep 10
 end 
end

我同时发出两个http请求并期望两个请求在10秒后返回输出,但是一个请求在10秒后返回输出,另一个请求在20秒后返回输出.因此,它证明它一次处理一个请求而不是同时处理.

这是否意味着乘客是单个进程服务器而不是多进程服务器?或者我错过了什么.

最佳答案 Passenger(以及大多数其他应用程序服务器)每个线程运行的请求不超过一个.通常,每个进程也只有一个线程.来自Phusion Passenger文档:

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.

(强调我自己)

点赞