gpt4 book ai didi

ruby-on-rails - rails : Passenger not serving multiple requests at a time

转载 作者:行者123 更新时间:2023-12-04 05:53:41 24 4
gpt4 key购买 nike

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

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

class Test < ApplicationController

def index
sleep 10
end
end

我同时点击了两个 http 请求,并期望两个请求在 10 秒后返回输出,但一个请求在 10 秒后返回输出,另一个请求在 20 秒后返回输出。所以它证明它一次处理一个请求,而不是同时处理。

这是否意味着乘客是单进程服务器而不是多进程服务器?或者我错过了一些东西。

最佳答案

乘客(以及大多数其他应用程序服务器)每个线程运行的请求不超过一个。通常每个进程也只有一个线程。从 Phusion 乘客文档:

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.



(强调我自己)

关于ruby-on-rails - rails : Passenger not serving multiple requests at a time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34373955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com