You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2023/04/14 10:45:37 UTC

[doris] branch master updated: [refactor](jdbc) using jvm parameters to init jdbc datasource (#18670)

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

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new e1b3955e05 [refactor](jdbc) using jvm parameters to init jdbc datasource (#18670)
e1b3955e05 is described below

commit e1b3955e0588c0bd5753f72539aa1a7d0a13fbcc
Author: zhangstar333 <87...@users.noreply.github.com>
AuthorDate: Fri Apr 14 18:45:29 2023 +0800

    [refactor](jdbc) using jvm parameters to init jdbc datasource (#18670)
    
    using the jvm parameters to init jdbc datasource connect pool.
    if anyone don't need to maintain the connect, so could set JDBC_MIN_POOL=0
---
 conf/be.conf                                         |  2 +-
 .../main/java/org/apache/doris/udf/JdbcExecutor.java | 20 ++++++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/conf/be.conf b/conf/be.conf
index ab65e76aec..3a3ec1e7de 100644
--- a/conf/be.conf
+++ b/conf/be.conf
@@ -18,7 +18,7 @@
 PPROF_TMPDIR="$DORIS_HOME/log/"
 
 CUR_DATE = `date +%Y%m%d-%H%M%S`
-JAVA_OPTS="-Xmx1024m -DlogPath=$DORIS_HOME/log/jni.log -Xlog:gc:$DORIS_HOME/log/be.gc.log.$CUR_DATE -Dsun.java.command=DorisBE -XX:-CriticalJNINatives"
+JAVA_OPTS="-Xmx1024m -DlogPath=$DORIS_HOME/log/jni.log -Xlog:gc:$DORIS_HOME/log/be.gc.log.$CUR_DATE -Dsun.java.command=DorisBE -XX:-CriticalJNINatives -DJDBC_MIN_POOL=1 -DJDBC_MAX_POOL=100 -DJDBC_MAX_IDEL_TIME=600000"
 
 # since 1.2, the JAVA_HOME need to be set to run BE process.
 # JAVA_HOME=/path/to/jdk/
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 f75debb01e..84b2a7d893 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
@@ -71,6 +71,10 @@ public class JdbcExecutor {
     private int curBlockRows = 0;
     private static final byte[] emptyBytes = new byte[0];
     private DruidDataSource druidDataSource = null;
+    private int minPoolSize = 1;
+    private int maxPoolSize = 100;
+    private int minIdleSize = 1;
+    private int maxIdelTime = 600000;
 
     public JdbcExecutor(byte[] thriftParams) throws Exception {
         TJdbcExecutorCtorParams request = new TJdbcExecutorCtorParams();
@@ -80,6 +84,10 @@ public class JdbcExecutor {
         } catch (TException e) {
             throw new InternalException(e.getMessage());
         }
+        minPoolSize = Integer.valueOf(System.getProperty("JDBC_MIN_POOL"));
+        maxPoolSize = Integer.valueOf(System.getProperty("JDBC_MAX_POOL"));
+        maxIdelTime = Integer.valueOf(System.getProperty("JDBC_MAX_IDEL_TIME"));
+        minIdleSize = minPoolSize > 0 ? 1 : 0;
         init(request.driver_path, request.statement, request.batch_size, request.jdbc_driver_class,
                 request.jdbc_url, request.jdbc_user, request.jdbc_password, request.op, request.table_type);
     }
@@ -228,16 +236,16 @@ public class JdbcExecutor {
                 ds.setUrl(jdbcUrl);
                 ds.setUsername(jdbcUser);
                 ds.setPassword(jdbcPassword);
-                ds.setMinIdle(1);
-                ds.setInitialSize(1);
-                ds.setMaxActive(100);
+                ds.setMinIdle(minIdleSize);
+                ds.setInitialSize(minPoolSize);
+                ds.setMaxActive(maxPoolSize);
                 ds.setMaxWait(5000);
-                ds.setTimeBetweenEvictionRunsMillis(600000);
-                ds.setMinEvictableIdleTimeMillis(300000);
+                ds.setTimeBetweenEvictionRunsMillis(maxIdelTime);
+                ds.setMinEvictableIdleTimeMillis(maxIdelTime / 2);
                 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
+                // and the default 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 + jdbcUser + jdbcPassword, ds);
             }


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