You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/13 15:23:18 UTC

[doris] 05/09: [refactor](jdbc) refactor jdbc connection num in datasource (#18563)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit a3a8cc9505f111c9a9719da2e9c961a135522397
Author: zhangstar333 <87...@users.noreply.github.com>
AuthorDate: Thu Apr 13 22:08:08 2023 +0800

    [refactor](jdbc) refactor jdbc connection num in datasource (#18563)
    
    now maybe jdbc have problem that there are too many connections and they do not release,
    so change the property of datasource: init = 1, min = 1, max = 100, and idle time is 10 minutes.
---
 .../main/java/org/apache/doris/external/jdbc/JdbcClient.java  |  6 ++++--
 .../src/main/java/org/apache/doris/udf/JdbcExecutor.java      | 11 +++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
index ffeec31e20..38a6f07b04 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
@@ -93,8 +93,10 @@ public class JdbcClient {
             dataSource.setUsername(jdbcUser);
             dataSource.setPassword(password);
             dataSource.setMinIdle(1);
-            dataSource.setInitialSize(2);
-            dataSource.setMaxActive(5);
+            dataSource.setInitialSize(1);
+            dataSource.setMaxActive(100);
+            dataSource.setTimeBetweenEvictionRunsMillis(600000);
+            dataSource.setMinEvictableIdleTimeMillis(300000);
             // set connection timeout to 5s.
             // The default is 30s, which is too long.
             // Because when querying information_schema db, BE will call thrift rpc(default timeout is 30s)
diff --git a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
index b1922ac45e..0a68857eb3 100644
--- a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
+++ b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
@@ -256,9 +256,16 @@ public class JdbcExecutor {
                 ds.setUsername(jdbcUser);
                 ds.setPassword(jdbcPassword);
                 ds.setMinIdle(1);
-                ds.setInitialSize(2);
-                ds.setMaxActive(5);
+                ds.setInitialSize(1);
+                ds.setMaxActive(100);
+                ds.setMaxWait(5000);
+                ds.setTimeBetweenEvictionRunsMillis(600000);
+                ds.setMinEvictableIdleTimeMillis(300000);
                 druidDataSource = ds;
+                // here is a cache of datasource, which using the string(jdbcUrl + jdbcUser +
+                // jdbcPassword) as key.
+                // and the datasource init = 1, min = 1, max = 100, if one of connection idle
+                // time greater than 10 minutes. then connection will be retrieved.
                 JdbcDataSource.getDataSource().putSource(jdbcUrl, ds);
             }
             conn = druidDataSource.getConnection();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org