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 c0d8ed56ac8026b4e3b93b42ad9153acd9f141be Author: zhangstar333 <87313068+zhangstar...@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 | 4 ++-- .../main/java/org/apache/doris/udf/JdbcExecutor.java | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/conf/be.conf b/conf/be.conf index cc1b8f6c59..d63b64bec1 100644 --- a/conf/be.conf +++ b/conf/be.conf @@ -17,8 +17,8 @@ PPROF_TMPDIR="$DORIS_HOME/log/" -DATE = `date +%Y%m%d-%H%M%S` -JAVA_OPTS="-Xmx1024m -DlogPath=$DORIS_HOME/log/jni.log -Xloggc:$DORIS_HOME/log/be.gc.log.$CUR_DATE -Dsun.java.command=DorisBE -XX:-CriticalJNINatives" +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 -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 0a68857eb3..5cff9a3534 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 @@ -72,6 +72,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(); @@ -81,6 +85,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); } @@ -255,16 +263,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, ds); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org