1. 程式人生 > >weblogic資料庫連線池引數配置詳解

weblogic資料庫連線池引數配置詳解

比較容易混淆的引數解釋

1:Inactive Connection Timeout

這個引數很重要,是10以後的版本新加的,9版本沒有,一般情況建議不要開啟該引數,即使開啟也儘可能要把數值設定大些,比如1800秒等。這個欄位的具體官方解釋在10.3.0.0的版本如下,在XX系統中實際反映的情況是,如果該引數設定為30(即:30S)的話,在大併發下會出現weblogic認為的leaked的連線,而且這時weblogic就會強制關閉這些連接回收,導致後續的應用獲取連線時報connection has alreadly been closed的異常,但如果把該引數禁用(設為0s),用同樣的大併發測試則一切正常,當連線池連線都被用時,連線請求會等待,超時會報取不到連線的異常,這些都是正常連線池的表現,這時在monitor中也沒有出現顯示Leaked 的連線。所以猜測Inactive Connection Timeout引數如果開啟的話應該會影響weblogic的

Leaked連線數的判斷方式,這個回頭做下試驗。。。

Automatically Recovering Leaked Connections

A leaked connection is a connection that was not properly returned to the connection pool in the data source. To automatically recover leaked connections, you can specify a value for Inactive Connection Timeout on the JDBC Data Source: Configuration: Connection Pool page in the Administration Console. When you set a value for Inactive Connection Timeout, WebLogic Server will forcibly return a connection to the data source when there is no activity on a reserved connection for the number of seconds that you specify

. When set to 0(the default value), this feature is turned off.

Note that the actual timeout could exceed the configured value for Inactive Connection Timeout. The internal data source maintenance thread runs every 5 seconds. When it reaches the Inactive Connection Timeout (for example 30 seconds), it checks for inactive connections. To avoid timing out a connection that was reserved just before the current check or just after the previous check, the server gives an inactive connection a “second chance.” On the next check, if the connection is still inactive, the server times it out and forcibly returns it to the data source. On average, there could be a delay of 50% more than the configured value.

2:connection reserve timeout

注意這個引數不是連線從連線池裡取出以後用來執行SQL等其它操作時的生命週期時間,而是當從連線池取連線時如果池裡的連線目前都正在被使用且池裡的連線數已經達到上限時,這個取連線動作的超時時間,在這個時間內會一直等著,超過這個時間就會報a Connection Unavailable SQL Exception,如果不設定這個時間,那麼出現連線達到上限還要取連線時會立即報a Connection Unavailable SQL Exception。具體看下面官方文件的解釋:

Enabling Connection Requests to Wait for a Connection

JDBC data sources have two attributes that you can set to enable connection requests to wait for a connection from a data source: Connection Reserve Timeout (ConnectionReserveTimeoutSeconds) and Maximum Waiting for Connection (HighestNumWaiters). You use these two attributes together to enable connection requests to wait for a connection without disabling your system by blocking too many threads.

See the  page in the Administration Console or see “” in the WebLogic Server MBean Reference for more details about these options.

Connection Reserve Timeout

When an application requests a connection from a data source, if all connections in the data source are in use and if the data source has expanded to its maximum capacity, the application will get a Connection Unavailable SQL Exception. To avoid this, you can configure the Connection Reserve Timeout value (in seconds) so that connection requests will wait for a connection to become available. After the Connection Reserve Timeout has expired, if no connection becomes available, the request will fail and the application will get aPoolLimitSQLException exception.

If you set Connection Reserve Timeout to -1, a connection request will timeout immediately if there is no connection available. If you set Connection Reserve Timeout to 0, a connection request will wait indefinitely. The default value is 10 seconds.

官方連線

--------------------------------------------------------------------------------------------------------------------------------

相關文件連結

Servers--JDBC--Data Sources--在右邊點選相應的資料來源--選擇Configuration下面的Connection Pool選項卡(這裡是該資料來源的連線池具體配置)

1.URL:

這裡配置的是資料庫的連線字串   如:jdbc:oracle:thin:@10.4.44.21:1521:airsm

2.Drive Class Name:

這裡配置的是資料庫的驅動類 如:oracle.jdbc.OracleDriver

3.Properties:

這裡配的是哪一個使用者使用該資料來源 如:user=aires

4.Initial Capacity:

這裡配的是初始化時的連線數(可配置如下:最小值: 0 ,最大值: 2147483647)

5.Maximum Capacity:

連線池中接點伺服器連線的最大數目,不要設定連線池的Initial Capacity和Maximum Capacity為一樣的數。這可能會導致出現兩個Oracle的節點伺服器,一個的CPU佔用已經達到99%-100%,而另外一個伺服器還是10%左右的情況(導致接點服務資源分配不均)

6.Capacity Increment:

連線池容量在最大容量限制範圍內的增量(每次增加的連線數)(可配置如下:最小值0 最大值2147483647)

7.Statement Cache Typeprepared statements:

快取的策略有如下兩個選項:

LRU:LRU演算法在有新的語句到來時,將最不經常被用得語句調整出快取

FIXED:FIXED演算法為先進先出的演算法

8.Statement Cache Size

巨集語句設定的靜態快取,大小由JDBC連線池配置時指定,調整這個數值的大小,有利於提高系統的效率(可配置如下:最小值0 最大值1024)

下面還有一些高階配置:

1.Test Table Name 

這裡是在我們配資料來源的過程中weblogic自動給我們配上的預設為SQL SELECT 1 FROM DUAL作用是在每次連線前對該連線先進行測試,該選項可以不配置

2.

Seconds to Trust an Idle Pool Connection:

該引數設定的是已經被使用的連線在多長時間內再次被使用不需要測試該連線(單位:秒)

3.Inactive Connection Timeout: 

當application取得connection後,在所設定的時間內沒有執行任何的動作,則此connection會被歸還到connection pool(單位為:秒)

最小值: 0 最大值: 2147483647

4.Maximum Waiting for Connection

假如connection pool的connection都被application使用,當有新的request需要使用connection時,所等待connection的時間(單位為:秒)

5.Connection Reserve Timeout:

連線保留超時時間相當於session,如過在web.xml和weblogic中同時配置,伺服器會以web.xml檔案中的配置為準,忽略weblogic中同時配置,(單位為:秒)

6.Statement Timeout:

限制connection執行SQL statement的時間(最小:-1 最大:2147483647)(單位為:秒,為-1時則不受限制)

7.Pinned-To-Thread(啟用需謹慎,對於併發量大的不推薦)

啟用後:當application關閉connection後,connection並無會回到connection pool,而是被keep在thread裡,因此假如application在同一個thread又需要使用connection時,可以馬上取得

特點:不受限' Maximum Capacity'引數

啟用前須確認系統可以承受大量的connection

8.Remove Infected Connections Enabled

啟用後:當application關閉connection後,WebLogic Server會自動重新建立一個新的connection,並放回到connection pool

使用 Pinned-To-Thread 屬性提高效能

要將應用程式保留資料來源中資料庫連線耗費的時間縮到最短,以及避免執行緒爭用資料庫連線,可將 Pinned-To-Thread 屬性新增到資料來源的“連線屬性”列表中,然後將其值設定為 true

啟用 Pinned-To-Thread 後,在應用程式首次使用某個執行執行緒保留連線時,WebLogic Server 會將資料來源中的一個數據庫連線固定到此執行緒。應用程式使用完該連線並呼叫 connection.close()(此方法在其他情況下將把連線返回資料來源)時,WebLogic Server 將把該連線留給執行執行緒,不會將其返回資料來源。當應用程式隨後使用同一執行執行緒請求連線時,WebLogic Server 將提供該執行緒已保留的連線。當多個執行緒嘗試同時保留一個連線時,該資料來源上不會發生鎖定衝突,對於嘗試保留有限個數的資料庫連線中同一個連線的執行緒,也沒有衝突。

注意: 在此版本中,Pinned-To-Thread 功能對多資料來源、Oracle RAC 和 IdentityPool 無效。如果出現連線故障,或連線標識不匹配,則這些功能依賴於將連線返回連線緩衝池後再重新將其獲取的能力。