首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails 3.2 + RESTful API慢速

Rails 3.2 + RESTful API慢速
EN

Stack Overflow用户
提问于 2012-10-16 06:48:12
回答 1查看 412关注 0票数 0

我正在开发一组RoR应用程序,并实现了一个API系统,让它们可以交换数据。

实现细节

  • rails 3.2.8
  • Ruby1.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-3秒,随后的调用速度为50 ms)。我认为这是延迟清单,因为APP4需要连接到APP*,那么连接就被处理了,对吗?

对调试/解决这个问题有什么建议吗?

非常感谢,毛罗

更新(2012-10-25年)

在API SRV应用程序上添加了输出(Ruby):https://gist.github.com/3950920

EN

回答 1

Stack Overflow用户

发布于 2012-11-15 10:16:54

我发现了问题,我想和你分享解决方案。

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

为了解决这个问题,我使用在http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerPreStart上找到的正确的乘客指令预加载应用程序

遵循我的rails配置:

代码语言:javascript
复制
# 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/
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12908969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档