《Druid數(shù)據(jù)庫連接池介紹》由會員分享,可在線閱讀,更多相關(guān)《Druid數(shù)據(jù)庫連接池介紹(16頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、溫紹錦(溫高鐵)http:/ Druid數(shù)據(jù)庫連接池的特點穩(wěn)定高效率可擴展可監(jiān)控可動態(tài)配置防SQL注入 穩(wěn)定阿里巴巴大規(guī)模部署應(yīng)用超過5 0 0個部署實例超過3 0 0 0最大集群超過6 0臺我們大規(guī)模使用中,開源連接池只有兩個是穩(wěn)定的: Druid DataSource Jboss DataSource (歷史原因還在使用) 穩(wěn)定的特性-ExceptionSorter當(dāng)連接產(chǎn)生不可恢復(fù)的異常時,需要及時從連接池中清除,否則會產(chǎn)生大量錯誤。這個功能也稱為ExceptionSorter,只有JBossDataSource和DruidDataSource實現(xiàn)了這個功能。 Oracle Fatal
2、ExcetionError Code2 8 Session has been killed6 0 0 Internal oracle error1 0 1 2 Not logged on1 0 1 4 Oracle shutdown in progress1 0 3 3 Oracle initialization or shutdown in progress1 0 3 4 Oracle not available1 0 3 5 ORACLE only available to users with RESTRICTED SESSION privilege1 0 8 9 Immediate s
3、hutdown in progres no operations are permitted1 0 9 0 Shutdown in progress no operations are permitted 1 0 9 2 ORACLE instance terminated. Disconnection forced1 0 9 4 ALTER DATABASE CLOSE in progress. Connections not permitted MySql Fatal ExceptionError Code1 0 4 0 ER_CON_COUNT_EEROR1 0 4 2 ER_BAD_H
4、OST_ERRROR1 0 4 3 ER_HANDSHAKE_ERROR1 0 4 7 ER_UNKOWN_COM_ERROR1 0 8 1 ER_IPSOCK_ERROR1 0 2 9 ER_HOST_IS_BLOCKED1 0 3 0 ER_HOST_NOT_PRIVILEGED1 0 4 5 ER_ACCESS_DENIED_ERROR1 0 0 4 ER_CANT_CREATE_FILE 1 0 0 5 ER_CANT_CREAT_TABLE1 0 1 5 ER_CANT_LOCK1 0 2 1 ER_DISK_FULL 高性能1 線程2 線程5 線程1 0 線程2 0線程5 0線程D
5、ruid 1 ,1 0 2 1 ,5 0 9 1 ,8 8 9 1 ,9 0 4 2 ,0 0 7 1 ,9 7 7Tomcat-jdbc 1 ,3 9 9 1 ,3 7 8 2 ,2 5 7 2 ,2 8 9 2 ,3 0 5 2 ,5 0 3DBCP 3 ,1 4 4 3 ,8 3 4 6 ,2 7 6 6 ,4 0 8 6 ,5 6 3 6 ,7 8 3BoneCP 4 ,3 2 7 3 ,5 9 8 3 ,8 0 0 5 ,2 4 2 9 ,4 0 2 1 9 ,0 6 6Jboss-Datasource 4 ,9 1 2 3 ,0 4 9 6 ,8 6 8 6 ,5 1 2 4 0
6、,1 4 6 4 3 ,7 4 8C3 P0 1 8 ,5 7 0 1 9 ,4 6 7 1 5 ,2 7 0 1 9 ,2 9 4 2 8 ,1 9 5 6 6 ,6 7 7Proxool 1 6 ,2 2 1 1 4 ,4 5 5 2 4 ,6 8 8 3 8 ,9 0 5 4 8 ,0 8 7(Error) 5 8 ,2 3 8(Error)詳細測試信息: https:/ %9 0 %8 4 %E7 %A7 %8 D%E8 %BF%9 E%E6 %8 E%A5 %E6 %B1 %A0 %E6 %8 0 %A7 %E8 %8 3 %BD%E5 %AF%B9 %E6 %AF%9 4 %E6
7、%B5 %8 B%E8 %AF%9 5Druid是目前性能最好的數(shù)據(jù)庫連接池 01 0 ,0 0 02 0 ,0 0 0 3 0 ,0 0 04 0 ,0 0 05 0 ,0 0 0 6 0 ,0 0 07 0 ,0 0 0 1 線程2 線程5 線程1 0 線程2 0線程5 0線程 DruidTomcat-jdbcDBCPBoneCPJboss-DatasourceC3 P0Proxool SQL Parser Parser基本概念詞法分析 Token語法分析抽象語法樹表達式語句 手寫Parser的性能 Cobar的SQL Parser,從Antlr生成的parser修改為Druid Pars
8、er之后,大約提升6倍的性能。 Druid Parser最近再次大幅度提升性能(5 0 %) SQL Parser的關(guān)鍵在于詞法詞法分析要支持預(yù)測 監(jiān)控 Spring關(guān)聯(lián)監(jiān)控 Web關(guān)聯(lián)監(jiān)控 查看SQL執(zhí)行明細配置filters=log4 j2013-07-12 16:10:17,966 DEBUG Connection:132 - conn-10001 connected2013-07-12 16:10:17,970 DEBUG Connection:132 - conn-10001 commited2013-07-12 16:10:17,970 DEBUG Connection:132 -
9、 conn 10001 rollback2013-07-12 16:10:17,983 DEBUG Statement:137 - conn-10001, stmt-20000 created2013-07-12 16:10:17,986 DEBUG Statement:137 - conn-10001, stmt-20000 executed. 0.052501 millis. SELECT 12013-07-12 16:10:17,986 DEBUG Statement:137 - conn-10001, stmt-20000 batch executed. 0.041842 millis
10、. SELECT 12013-07-12 16:10:18,205 DEBUG Statement:137 - conn-10001, stmt-20000, rs-50000 query executed. 219.082247 millis. SELECT 1 2013-07-12 16:10:18,205 DEBUG ResultSet:142 - conn-10001, stmt-20000, rs-50000 open2013-07-12 16:10:18,206 DEBUG ResultSet:142 - conn-10001, stmt-20000, rs-50000 Heade
11、r: null2013-07-12 16:10:18,206 DEBUG Statement:137 - conn-10001, stmt-20000 update executed. effort 0. 0.019343 millis. SELECT 12013-07-12 16:10:18,223 DEBUG Statement:137 - conn-10001, pstmt-20001 created. SELECT 12013-07-12 16:10:18,260 DEBUG Statement:137 - conn-10001, pstmt-20001 Parameters : nu
12、ll, null, null, null, com.alibaba.druid.mock.MockBlob34aee875, 1, B471f7458, null, com.alibaba.druid.mock.MockClob620f61e2, null, 1.0, 1, 1, null, com.alibaba.druid.mock.MockNClob5fe36eb9, null, null, null, com.alibaba.druid.mock.MockRef4c7a64dd, com.alibaba.druid.mock.MockRowId77741064, 1, com.alib
13、aba.druid.mock.MockSQLXML64e05280, , null, null, null, null2013-07-12 16:10:18,260 DEBUG Statement:137 - conn-10001, pstmt-20001 Types : ARRAY, OTHER, DECIMAL, OTHER, BLOB, TINYINT, OTHER, OTHER, CLOB, DATE, FLOAT, INTEGER, BIGINT, OTHER, NCLOB, NVARCHAR, VARCHAR, OTHER, REF, ROWID, SMALLINT, SQLXML
14、, VARCHAR, TIME, TIMESTAMP, OTHER, OTHER2013-07-12 16:10:18,260 DEBUG Statement:137 - conn-10001, pstmt-20001 executed. 0.564872 millis. SELECT 12013-07-12 16:10:18,260 DEBUG Statement:137 - conn-10001, pstmt-20001 batch executed. 0.0075 millis. SELECT 12013-07-12 16:10:18,260 DEBUG Statement:137 -
15、conn-10001, pstmt-20001 Parameters : null, null, null, null, com.alibaba.druid.mock.MockBlob34aee875, 1, B471f7458, null, com.alibaba.druid.mock.MockClob620f61e2, null, 1.0, 1, 1, null, com.alibaba.druid.mock.MockNClob5fe36eb9, null, null, null, com.alibaba.druid.mock.MockRef4c7a64dd, com.alibaba.dr
16、uid.mock.MockRowId77741064, 1, com.alibaba.druid.mock.MockSQLXML64e05280, , null, null, null, null2013-07-12 16:10:18,262 DEBUG Statement:137 - conn-10001, pstmt-20001 Types : ARRAY, OTHER, DECIMAL, OTHER, BLOB, TINYINT, OTHER, OTHER, CLOB, DATE, FLOAT, INTEGER, BIGINT, OTHER, NCLOB, NVARCHAR, VARCH
17、AR, OTHER, REF, ROWID, SMALLINT, SQLXML, VARCHAR, TIME, TIMESTAMP, OTHER, OTHER2013-07-12 16:10:18,262 DEBUG Statement:137 - conn-10001, pstmt-20001, rs-50001 query executed. 1.805932 millis. SELECT 12013-07-12 16:10:18,262 DEBUG ResultSet:142 - conn-10001, pstmt-20001, rs-50001 open2013-07-12 16:10
18、:18,263 DEBUG ResultSet:142 - conn-10001, pstmt-20001, rs-50001 Header: null2013-07-12 16:10:18,263 DEBUG Statement:137 - conn-10001, pstmt-20001 Parameters : null, null, null, null, com.alibaba.druid.mock.MockBlob34aee875, 1, B471f7458, null, com.alibaba.druid.mock.MockClob620f61e2, null, 1.0, 1, 1
19、, null, com.alibaba.druid.mock.MockNClob5fe36eb9, null, null, null, com.alibaba.druid.mock.MockRef4c7a64dd, com.alibaba.druid.mock.MockRowId77741064, 1, com.alibaba.druid.mock.MockSQLXML64e05280, , null, null, null, null2013-07-12 16:10:18,263 DEBUG Statement:137 - conn-10001, pstmt-20001 Types : AR
20、RAY, OTHER, DECIMAL, OTHER, BLOB, TINYINT, OTHER, OTHER, CLOB, DATE, FLOAT, INTEGER, BIGINT, OTHER, NCLOB, NVARCHAR, VARCHAR, OTHER, REF, ROWID, SMALLINT, SQLXML, VARCHAR, TIME, TIMESTAMP, OTHER, OTHER 2013-07-12 16:10:18,263 DEBUG Statement:137 - conn-10001, pstmt-20001 update executed. effort 0. 0
21、.287765 millis. SELECT 12013-07-12 16:10:18,274 DEBUG Statement:137 - conn-10001, cstmt-20002 created. SELECT 12013-07-12 16:10:18,274 DEBUG Statement:137 - conn-10001, stmt-20000, rs-50002 query executed. 0.081711 millis. SELECT 12013-07-12 16:10:18,274 DEBUG ResultSet:142 - conn-10001, stmt-20000,
22、 rs-50002 open2013-07-12 16:10:18,274 DEBUG ResultSet:142 - conn-10001, stmt-20000, rs-50002 Header: null2013-07-12 16:10:18,275 DEBUG ResultSet:142 - conn-10001, stmt-20000, rs-50002 Result: 1 防御SQL注入配置filters=“wall”智能攔截永真條件智能攔截系統(tǒng)函數(shù)調(diào)用智能攔截系統(tǒng)表訪問 集中配置、動態(tài)配置 filters=“config”支持?jǐn)?shù)據(jù)庫密碼加密支持從本地或者http遠程讀取配置文件