0

私は RoR アプリケーションのコレクションに取り組んでおり、それらがデータを交換できるように API システムを実装しました。

実装の詳細

ライブラリ

  • レール3.2.8
  • ルビー 1.9.2 p320
  • jbuilder 0.8.2 (API サービス)
  • httparty 0.9.0 (API cli)

認可

API にアクセスするには、アクセス トークンが必要です

安全

開発環境での自己署名 SSL 証明書。アクセス トークンが盗まれるのを防ぐために、API 呼び出しに SSL を使用します (httparty は自動的に SSL 警告を無視します)。

シナリオ

APP1 は API を提供するデータを公開します

APP2 は API を提供するデータを公開します

APP3 は API を提供するデータを公開します

APP4 は APP1、APP2、APP3 データを必要とし、それを取得するために API を使用します。

問題

API への最初の呼び出しは低速です (各アプリで 2 ~ 3 秒の遅延、その後の呼び出しは最大 50 ミリ秒高速です)。APP4 は APP* に接続する必要があるため、遅延マニフェストだと思います。その後、接続が維持されます。これでよろしいですか?

問題をデバッグ/解決するための提案はありますか?

どうもありがとう、マウロ

更新 (2012-10-25)

API SRV APP に出力 (ruby-prof) を追加: https://gist.github.com/3950920

4

1 に答える 1

0

問題を見つけたので、解決策をあなたと共有したいと思います。

デフォルトでは、Passenger は必要に応じてアプリケーションを立ち上げます (メモリや CPU を節約するためなど)。このため、各アプリケーション (APP1、APP2、APP3) の API への最初の呼び出しには、最大 2 ~ 3 秒かかりました。

この問題を解決するために、 http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerPreStartにある正しい Passenger ディレクティブを使用してアプリケーションをプリロードします。

私のレール構成に従います:

# 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/
于 2012-11-15T10:16:54.180 に答える