我发现了问题,我想与您分享解决方案。
默认情况下,Passenger 在需要时启动应用程序(以节省内存、cpu 等)。因此,对每个应用程序(APP1、APP2 和 APP3)的 API 的第一次调用最多需要 2 - 3 秒。
为了解决这个问题,我使用http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerPreStart上的正确乘客指令预加载应用程序
遵循我的 rails 配置:
# Load passenger module and set paths
# The following three lines MUST be updated whenever the 'passenger-install-apache2-module' is executed
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p286/ruby
# Speeds up spawn time tremendously -- if your app is compatible.
# RMagick seems to be incompatible with smart spawning
# Older versions of Passenger called this RailsSpawnMethod
PassengerSpawnMethod smart
# Keep the application instances alive longer. Default is 300 (seconds)
PassengerPoolIdleTime 1000
# Keep the spawners alive, which speeds up spawning a new Application
# listener after a period of inactivity at the expense of memory.
RailsAppSpawnerIdleTime 0
# Just in case you're leaking memory, restart a listener
# after processing 5000 requests
PassengerMaxRequests 5000
# Automatically hit your site when apache starts, so that you don't have to wait
# for the first request for passenger to "spin up" your application. This even
# helps when you have smart spawning enabled.
PassengerPreStart http://app1.mydomain.com/
PassengerPreStart http://app2.mydomain.com/
PassengerPreStart http://app3.mydomain.com/
PassengerPreStart http://app4.mydomain.com/