1

最近、RailsがPostgreSQLへの接続をドロップし、リクエストごとに複数の再接続が発生し、リクエストの速度が大幅に低下するという問題が発生しました。私は現在、次の環境でMacOSX上ですべてをローカルで実行しています。

  • Mac OS X 10.8(マウンテンライオン)
  • 捕虜
  • NginX(sslアンラッピング-これを有効にしなくても同じアプリの再接続動作)
  • Homebrew経由のPostgreSQL9.2.2
  • Rails 3.2.11

これが私のdatabase.yml:(データベースとユーザー名が編集されました)

development:
  adapter: postgresql
  encoding: unicode
  database: <database>
  pool: 5
  username: <user>
  password:

これは、development.log典型的なリクエスト中の出力です:(特定のモデルとレンダリングが編集されました)

Connecting to database specified by database.yml


Started GET "/" for 127.0.0.1 at 2013-02-05 12:25:38 -0800
Processing by HomeController#index as HTML
  ... <app performs model loads and render calls>
Completed 200 OK in 314ms (Views: 196.0ms | ActiveRecord: 60.9ms)
Connecting to database specified by database.yml
Connecting to database specified by database.yml

また、Postgresでステートメントロギングを有効にして、特定のリクエスト中にデータベース側で何が起こっていたかをより正確に把握できるようにしました。postgresql-<date>.logこれが:(編集された私のアプリに固有のクエリ)からの出力です

LOG:  connection received: host=[local]
LOG:  connection authorized: user=<user> database=<database>
LOG:  statement: set client_encoding to 'UTF8'
LOG:  statement: set client_encoding to 'unicode'
LOG:  statement: SHOW client_min_messages
LOG:  statement: SET client_min_messages TO 'panic'
LOG:  statement: SET standard_conforming_strings = on
LOG:  statement: SET client_min_messages TO 'notice'
LOG:  statement: SET time zone 'UTC'
LOG:  statement: SHOW TIME ZONE
LOG:  statement: SELECT 1
LOG:  statement: SELECT 1
    ... <app makes queries for request>
LOG:  disconnection: session time: 0:00:01.346 user=<user> database=<database> host=[local]
LOG:  connection received: host=[local]
LOG:  connection authorized: user=<user> database=<database>
LOG:  statement: set client_encoding to 'UTF8'
LOG:  statement: set client_encoding to 'unicode'
LOG:  statement: SHOW client_min_messages
LOG:  statement: SET client_min_messages TO 'panic'
LOG:  statement: SET standard_conforming_strings = on
LOG:  statement: SET client_min_messages TO 'notice'
LOG:  statement: SET time zone 'UTC'
LOG:  statement: SHOW TIME ZONE
LOG:  statement: SELECT 1
LOG:  connection received: host=[local]
LOG:  connection authorized: user=<user> database=<database>
LOG:  statement: set client_encoding to 'UTF8'
LOG:  statement: set client_encoding to 'unicode'
LOG:  statement: SHOW client_min_messages
LOG:  statement: SET client_min_messages TO 'panic'
LOG:  statement: SET standard_conforming_strings = on
LOG:  statement: SET client_min_messages TO 'notice'
LOG:  statement: SET time zone 'UTC'
LOG:  statement: SHOW TIME ZONE
LOG:  statement: SELECT 1
LOG:  statement: SELECT 1
LOG:  statement: SELECT 1
LOG:  disconnection: session time: 0:00:00.750 user=<user> database=<database> host=[local]
LOG:  disconnection: session time: 0:00:00.733 user=<user> database=<database> host=[local]

コマンド呼び出しに関連する構成またはログ出力で更新できてうれしいです。また、なぜすべてのSELECT 1呼び出しですか?彼らの目的は何ですか?

ありがとう!

4

1 に答える 1

0

答えは、PostgreSQLを新しいバージョンにアップグレードすることです。9.2.4元の質問で使用されていたものからにアップグレードした9.2.2ところ、問題は完全に解消され、期待されるパフォーマンス特性が開発アプリケーションに戻ってきました。

于 2013-05-05T09:11:42.873 に答える