2012-10-16 45 views
0

我正在研究RoR应用程序的集合,并且实现了一个API系统来让它们交换数据。Rails 3.2 + RESTful API slow

实现细节

  • 轨3.2.8
  • 红宝石1.9.2 P320
  • JBuilder的0.8.2(API SRV)
  • httparty 0.9。 0(API cli)

授权

访问令牌需要,以获得对API

安全

自签署开发环境SSL证书,在线访问。 将SSL用于API调用以防止访问令牌被盗(httparty会自动忽略SSL警告)。

情景

APP1暴露数据提供API

APP2暴露数据提供API

APP3暴露数据提供API

APP4需要APP1,APP2,APP3数据和使用API​​来获取它。

问题

给API的第一呼叫是缓慢的(2 - 延迟对于每个APP的3秒,随后的调用是快〜50毫秒)。我认为这是延迟清单,因为APP4需要连接到APP *,然后连接被完成,这是正确的吗?

任何建议调试/解决问题?

非常感谢, 莫罗

更新(2012年10月25日)

的API SRV APP

新增输出(红宝石教授): https://gist.github.com/3950920

+0

请问开关红宝石1.9.3-P286(最近发布)解决问题? –

+0

这里真的没有足够的信息来说。我们必须看到日志,代码,请求等。但是你可以尝试自己的分析,像ruby-prof这样的东西。 – sevenseacat

回答

0

,我发现这个问题,我想与你分享解决方案。

默认情况下,乘客在需要时调出应用程序(为了节省内存,cpu,...)。因此,每个应用程序的API(APP1,APP2 & APP3)的第一次调用花费了2-3秒。

为了解决我使用预装在http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerPreStart找到正确的乘客指示申请问题

跟随我的导轨配置:

# 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/