0
我最近遇到了一個問題,Rails將連接丟到我的PostgreSQL上,導致每個請求發生多次重新連接,從而顯着減慢請求速度。我目前運行在Mac OS X的一切地方有以下環境:使用PostgreSQL的Rails每次請求重新連接多次
- 的Mac OS X 10.8(山獅)
- 戰俘
- NGINX(SSL解包 - 相同的應用程序重新連接行爲,即使沒有啓用此功能)通過自制
- 的PostgreSQL 9.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]
我很高興與相關CONFIGS更新的日誌記錄或命令調用輸出。另外,爲什麼所有的SELECT 1
調用?他們的目的是什麼?
謝謝!