<VirtualHost *:80> ServerName www.example.com DocumentRoot /webapps/my_app/public PassengerMaxRequestTime 2 <Location /expensive_computation> PassengerMaxRequestTime 10 </Location> </VirtualHost>
Phusion Passenger is an Apache module, which makes deploying Ruby and Ruby on Rails applications on Apache a breeze. It follows the usual Ruby on Rails conventions, such as "Don’t-Repeat-Yourself" and ease of setup, while at the same time providing enough flexibility.
This guide documents the features that are only available in Phusion Passenger Premium (i.e. features that are not available on Phusion Passenger open source edition). For general Phusion Passenger documentation, such as installation instructions and troubleshooting, please refer to the Phusion Passenger users guide
The maximum amount of memory that an application instance may use, in megabytes. Once an application instance has surpassed its memory limit, it will process all the requests currently present in its queue and then shut down. A value of 0 means that there is no maximum: the application’s memory usage will not be checked.
This option is useful if your application is leaking memory. By shutting it down, all of its memory is guaranteed to be freed by the operating system.
This option may occur in the following places:
In the global server configuration.
In a virtual host configuration block.
In a <Directory> or <Location> block.
In .htaccess, if AllowOverride Limits is on.
In each place, it may be specified at most once. The default value is 200.
Note
|
A word about permissions
The PassengerMemoryLimit directive requires that the user that the application is running as (see PassengerUserSwitching) to have access to the /proc file system, or to be able to inspect its status with ps (which on Linux and FreeBSD systems basically means the same thing, since ps reads process information from /proc). Therefore, on servers running with tight permissions on /proc, this directive may not work. If you wish to use this directive and your /proc permissions are too tight, then please consider untightening the permissions. |
Tip
|
FreeBSD and /proc
On many FreeBSD systems, /proc is not mounted by default. /proc must be mounted in order for PassengerMemoryLimit to work. It is also advised that you mount /proc with the linprocfs filesystem type instead of the regular FreeBSD proc filesystem type. The linprocfs filesystem type allows Phusion Passenger to read memory information from /proc directly, which is very fast. If you mount /proc with a different filesystem type, then Phusion Passenger must resort to querying memory information from the ps command, which is a lot slower. |
Caution
|
The PassengerMaxRequests and PassengerMemoryLimit directives should be considered as workarounds for misbehaving applications. It is advised that you fix the problem in your application rather than relying on these directives as a measure to avoid memory leaks. |
The maximum number of application instances that may be simultaneously active for an application. This helps to make sure that a single application will not occupy all available slots in the application pool.
This value must be less than PassengerMaxPoolSize. A value of 0 means that there is no limit placed on the number of instances a single application may use, i.e. only the global limit of PassengerMaxPoolSize will be enforced.
This option may occur in the following places:
In the global server configuration.
In a virtual host configuration block.
In each place, it may be specified at most once. The default value is 0.
Tip
|
Practical usage example
Suppose that you’re hosting two web applications on your server, a personal blog and an e-commerce website. You’ve set PassengerMaxPoolSize to 10. The e-commerce website is more important to you. You can then set PassengerMaxInstances to 3 for your blog, so that it will never use more than 3 pool slots, even if it suddenly gets a lot of traffic. Your e-commerce website on the other hand will be free to use up all 10 slots if it gets a lot of traffic. |
The maximum amount of time, in seconds, that an application instance may take to process a request. If the request takes longer than this amount of time, then the application instance will be forcefully shut down, and restarted upon the next request. A value of 0 means that there is no time limit.
This option is useful for preventing your application from freezing for an indefinite period of time.
This option may occur in the following places:
In the global server configuration.
In a virtual host configuration block.
In a <Directory> or <Location> block.
In .htaccess, if AllowOverride Limits is on.
In each place, it may be specified at most once. The default value is 0.
Suppose that most of your requests are known to finish within 2 seconds. However, there is one URI, /expensive_computation, which is known to take up to 10 seconds. You can then configure Phusion Passenger as follows:
<VirtualHost *:80> ServerName www.example.com DocumentRoot /webapps/my_app/public PassengerMaxRequestTime 2 <Location /expensive_computation> PassengerMaxRequestTime 10 </Location> </VirtualHost>
If a request to /expensive_computation takes more than 10 seconds, or if a request to any other URI takes more than 2 seconds, then the corresponding application instance will be forced to shutdown.
Caution
|
The PassengerMaxRequestTime directive should be considered as a workaround for misbehaving applications. It is advised that you fix the problem in your application rather than relying on these directives as a measure to avoid freezing applications. |