我正在开发一组RoR应用程序,并实现了一个API系统,让它们可以交换数据。
实现细节
库
授权
为了访问API,需要一个访问令牌。
安全性
开发环境中的自签名SSL证书。使用SSL进行API调用,以防止访问令牌被窃取(httparty自动忽略SSL警告)。
场景
APP1公开提供API的数据。
APP2公开提供API的数据。
APP3公开提供API的数据。
APP4需要APP1、APP2、APP3数据,并使用API来获取数据。
问题
对API的第一次调用是缓慢的(每个应用程序延迟2-3秒,随后的调用速度为50 ms)。我认为这是延迟清单,因为APP4需要连接到APP*,那么连接就被处理了,对吗?
对调试/解决这个问题有什么建议吗?
非常感谢,毛罗
更新(2012-10-25年)
在API SRV应用程序上添加了输出(Ruby):https://gist.github.com/3950920
发布于 2012-11-15 10:16:54
我发现了问题,我想和你分享解决方案。
默认情况下,乘客在需要时会打开应用程序(以节省内存、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/https://stackoverflow.com/questions/12908969
复制相似问题