DBCP2 - When remote connections are removed from the pool

When configuring the DBCP2 pool and based on the documentation, I noticed that there is a configuration called timeBetweenEvictionRunsMilliswhich is described as:

Waiting time, in milliseconds, between starts of a stream of the evictor of an unallocated object. If the value is not positive, the empty object evictor stream will not be started.

Its default value is -1.

Does this mean that the evictor stream will never work in the default configuration? Whereas maxIdlethe configuration parameter is applied maxIdle, the pool must maxIdleconnect if there are more than maxIdle.

I am very confused that the default configuration is such that empty connections are never excluded.

There is also another configuration softMiniEvictableIdleTimeMillisthat seems to play a role on top timeBetweenEvictionRunsMillis.

Any clarification in this regard would be of great help.

I am currently setting up the pool as shown below - since my goal is to not have any idle connections in my pool for too long (this was necessary since we are using AWS RDS, and there seems to be a strange problem, which we often encounter)

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl(properties.getProperty("app.mysql.url"));
    dataSource.setUsername(properties.getProperty("app.mysql.username"));
    dataSource.setPassword(properties.getProperty("app.mysql.password"));
    dataSource.setMaxIdle(20);
    dataSource.setMaxWaitMillis(20000); //wait 10 seconds to get new connection
    dataSource.setMaxTotal(200);
    dataSource.setMinIdle(0);
    dataSource.setInitialSize(10);
    dataSource.setTestOnBorrow(true);
    dataSource.setValidationQuery("select 1");
    dataSource.setValidationQueryTimeout(10); //The value is in seconds

    dataSource.setTimeBetweenEvictionRunsMillis(600000); // 10 minutes wait to run evictor process
    dataSource.setSoftMinEvictableIdleTimeMillis(600000); // 10 minutes wait to run evictor process
    dataSource.setMinEvictableIdleTimeMillis(60000); // 60 seconds to wait before idle connection is evicted
    dataSource.setMaxConnLifetimeMillis(600000); // 10 minutes is max life time
    dataSource.setNumTestsPerEvictionRun(10);
+8
source share
2 answers

, evictor . , maxIdle maxTotal , , , . , , .

maxIdle maxTotal evictor, , . , , maxIdle.

minEvictableIdleTimeMillis softMinEvictableIdleTimeMillis (, , , ...MinEvictalbe..., ...MiniEvictable...). , minIdle, . , , softMinEvictableIdleTimeMillis minEvictableIdleTimeMillis.

, minEvictableIdleTimeMillis=10000 softMinEvictableIdleTimeMillis=-1 ( ). 10 . minIdle, . minIdle, .

, minEvictableIdleTimeMillis=10000 softMinEvictableIdleTimeMillis=30000. minEvictableIdleTimeMillis softMinEvictableIdleTimeMillis. , . minEvictableIdleTimeMillis.

, maxTotal maxIdle, maxIdle minIdle minEvictableIdleTimeMillis, minIdle 0 softMinEvictableIdleTimeMillis . .

, 20. 20 10 20 ( ), 10 EvictableIdleTimeMillis 10 TimeBetweenEvictionRunsMillis.

maxIdle maxTotal. , maxIdle , . , ( db ) ( TIME_WAIT, ).

+12
'if my maxtotal and maxidle are set to 20 and 
 minindle = 5
 minEvictableIdleTimeMillis = -1
 softMinEvictableIdleTimeMillis = 300000
 timeBetweenEvictionRunsMillis =180000 
 can you explain how on a heavy load and low load will the pool behave?'
0

Source: https://habr.com/ru/post/1649693/


All Articles