Phusion Passenger如何重用线程和进程?

时间:2022-10-06 08:32:26

I am setting up an Apache2 webserver running multiple Ruby on Rails web applications with Phusion Passenger. I know that Passenger spawns Ruby processes for handling requests. I have the following questions:

我正在建立一个使用Phusion Passenger运行多个Ruby on Rails Web应用程序的Apache2 Web服务器。我知道Passenger会生成Ruby进程来处理请求。我有以下问题:

  • If more than one request has to be handled at the same time, will Passenger spawn multiple processes or multiple (Ruby) threads? How do I configure it so it always spawns single-threaded processes?
  • 如果必须同时处理多个请求,Passenger会产生多个进程还是多个(Ruby)线程?如何配置它以便始终生成单线程进程?
  • If I have two Rails applications, imagine that a request for app A goes to process 1, then later request for app B arrives. Is it possible that process 1 will handle this request as well? When and how is this possible? In other words, is one process allowed to handle requests for multiple Rails applications?
  • 如果我有两个Rails应用程序,想象一下对应用程序A的请求进入进程1,然后请求应用程序B到达。流程1是否也可以处理此请求?何时以及如何实现?换句话说,是否允许一个进程处理多个Rails应用程序的请求?
  • I have the same Rails application exported in multiple URLs and multiple virtual hosts (such as http:// and https://). Will the same process be able to serve different virtual hosts? (The answer to this seems to be yes, I've set a global variable in answering a request to virtual host A, and I was able to retrieve the value in virtual host B.)
  • 我在多个URL和多个虚拟主机(例如http://和https://)中导出了相同的Rails应用程序。同一个进程是否能够为不同的虚拟主机提供服务? (答案似乎是肯定的,我在回答虚拟主机A的请求时设置了一个全局变量,并且我能够在虚拟主机B中检索该值。)

2 个解决方案

#1


12  

Generally speaking, Passenger spawns new processes by forking an ApplicationSpawner, which has the framework and application code pre-loaded into memory, or a FrameworkSpawner, which just has the framework code.

一般来说,Passenger通过分支ApplicationSpawner产生新进程,ApplicationSpawner具有预先加载到内存中的框架和应用程序代码,或者FrameworkSpawner,它只具有框架代码。

Passenger, as far as I know, doesn't deal in threads. Instead, as the load increases on an application, it will fork that Application's ApplicationSpawner and initialize another instance. When load decreases, one or more application instances are killed off.

据我所知,乘客不会处理线程。相反,随着应用程序上的负载增加,它将分叉该Application的ApplicationSpawner并初始化另一个实例。当负载减少时,一个或多个应用程序实例将被终止。

If Passenger is configured in a certain way (I believe by choosing the "smart" spawn method), it will create a FrameworkSpawner, which loads the rails code, but no application code, which can then be forked to load and application using that version of Rails.

如果Passenger以某种方式配置(我相信通过选择“智能”spawn方法),它将创建一个FrameworkSpawner,它加载rails代码,但没有应用程序代码,然后可以使用该版本分叉加载和应用程序Rails。

So to answer your questions:

所以回答你的问题:

  • It will serve them sequentially, then spawn additional processes if it decides the load is high enough.

    它将按顺序为它们提供服务,如果它确定负载足够高,则会产生其他进程。

  • No. One process can only belong to a single Rails Application.

    不可以。一个进程只能属于一个Rails应用程序。

  • I'm kind of sketchy on this one, but your experiment makes sense. Passenger should be smart enough to figure out that even though it's running from different places in the server config, you're talking about the same application. It's probably based on the application's filesystem path.

    我对这个有点粗略,但你的实验很有意义。乘客应该足够聪明,即使它从服务器配置中的不同位置运行,你也在谈论相同的应用程序。它可能基于应用程序的文件系统路径。

EDIT: I went and read up on this a bit. Turns out I was mostly right, but the technical details were a bit off. See the Passenger documentation

编辑:我去读了一下这个。事实证明我大部分是正确的,但技术细节有点偏。请参阅Passenger文档

#2


6  

Yup, Burke is right. In case of the third question, Phusion Passenger recognizes applications by their application root path. So even if you have two virtual hosts, if they both point to the same DocumentRoot then Phusion Passenger will think that they're the same app.

是的,伯克是对的。在第三个问题的情况下,Phusion Passenger通过其应用程序根路径识别应用程序。因此,即使您有两个虚拟主机,如果它们都指向同一个DocumentRoot,那么Phusion Passenger会认为它们是相同的应用程序。

#1


12  

Generally speaking, Passenger spawns new processes by forking an ApplicationSpawner, which has the framework and application code pre-loaded into memory, or a FrameworkSpawner, which just has the framework code.

一般来说,Passenger通过分支ApplicationSpawner产生新进程,ApplicationSpawner具有预先加载到内存中的框架和应用程序代码,或者FrameworkSpawner,它只具有框架代码。

Passenger, as far as I know, doesn't deal in threads. Instead, as the load increases on an application, it will fork that Application's ApplicationSpawner and initialize another instance. When load decreases, one or more application instances are killed off.

据我所知,乘客不会处理线程。相反,随着应用程序上的负载增加,它将分叉该Application的ApplicationSpawner并初始化另一个实例。当负载减少时,一个或多个应用程序实例将被终止。

If Passenger is configured in a certain way (I believe by choosing the "smart" spawn method), it will create a FrameworkSpawner, which loads the rails code, but no application code, which can then be forked to load and application using that version of Rails.

如果Passenger以某种方式配置(我相信通过选择“智能”spawn方法),它将创建一个FrameworkSpawner,它加载rails代码,但没有应用程序代码,然后可以使用该版本分叉加载和应用程序Rails。

So to answer your questions:

所以回答你的问题:

  • It will serve them sequentially, then spawn additional processes if it decides the load is high enough.

    它将按顺序为它们提供服务,如果它确定负载足够高,则会产生其他进程。

  • No. One process can only belong to a single Rails Application.

    不可以。一个进程只能属于一个Rails应用程序。

  • I'm kind of sketchy on this one, but your experiment makes sense. Passenger should be smart enough to figure out that even though it's running from different places in the server config, you're talking about the same application. It's probably based on the application's filesystem path.

    我对这个有点粗略,但你的实验很有意义。乘客应该足够聪明,即使它从服务器配置中的不同位置运行,你也在谈论相同的应用程序。它可能基于应用程序的文件系统路径。

EDIT: I went and read up on this a bit. Turns out I was mostly right, but the technical details were a bit off. See the Passenger documentation

编辑:我去读了一下这个。事实证明我大部分是正确的,但技术细节有点偏。请参阅Passenger文档

#2


6  

Yup, Burke is right. In case of the third question, Phusion Passenger recognizes applications by their application root path. So even if you have two virtual hosts, if they both point to the same DocumentRoot then Phusion Passenger will think that they're the same app.

是的,伯克是对的。在第三个问题的情况下,Phusion Passenger通过其应用程序根路径识别应用程序。因此,即使您有两个虚拟主机,如果它们都指向同一个DocumentRoot,那么Phusion Passenger会认为它们是相同的应用程序。