2014-11-03 44 views
1

我在一機在另一臺機器上運行兩個Web應用程序和一個DB「同時發送給後端的I/O錯誤發生」(它們使用相同的DB) 一個可以運行得很好,但另一種。約4小時後總是下降。PostgreSQL的例外:

下面是錯誤信息:

Error 2014-11-03 13:31:05,902 [http-bio-8080-exec-7] ERROR spi.SqlExceptionHelper - An I/O error occured while sending to the backend. 
| Error 2014-11-03 13:31:05,904 [http-bio-8080-exec-7] ERROR spi.SqlExceptionHelper - This connection has been closed. 

PostgreSQL的日誌:

2014-10-26 23:41:31 CDT WARNING: pgstat wait timeout 
2014-10-27 01:13:48 CDT WARNING: pgstat wait timeout 
2014-10-27 03:55:46 CDT LOG: could not receive data from client: Connection timed out 
2014-10-27 03:55:46 CDT LOG: unexpected EOF on client connection 

是誰造成這個問題,應用程序或數據庫?或網?

+0

網絡連接,很可能是NAT連接跟蹤表到期。 – 2014-11-03 13:25:32

回答

1

原因:

在這一點上,很明顯,這是閒置的TCP連接已經被打破,但我們的應用程序仍然認爲它是開放的。空閒連接是指應用程序暫時未在使用的池中的連接。

一些搜索後,我來到了我的應用程序和數據庫之間的網絡防火牆在1小時後丟棄空閒/陳舊連接的結論。這似乎是很多人遇到的常見問題。

解決方案:

Grails中,你可以設置這DataSource.groovy中。

environments { 
    development { 
     dataSource { 
      //configure DBCP 
      properties { 
       maxActive = 50 
       maxIdle = 25 
       minIdle = 1 
       initialSize = 1 
       minEvictableIdleTimeMillis = 60000 
       timeBetweenEvictionRunsMillis = 60000 
       numTestsPerEvictionRun = 3 
       maxWait = 10000 

       testOnBorrow = true 
       testWhileIdle = true 
       testOnReturn = false 

       validationQuery = "SELECT 1" 
      } 
     } 
    } 
}