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

tanxinyu pushed a commit to branch master_performance
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master_performance by this 
push:
     new 85cd9fa  fix
85cd9fa is described below

commit 85cd9fa0d4470b39141b9278a36b341729864ba3
Author: LebronAl <[email protected]>
AuthorDate: Fri Jan 14 14:03:34 2022 +0800

    fix
---
 .../iotdb/cluster/client/ClientPoolFactory.java    |  1 +
 .../cluster/client/ClientPoolFactoryTest.java      | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git 
a/cluster/src/main/java/org/apache/iotdb/cluster/client/ClientPoolFactory.java 
b/cluster/src/main/java/org/apache/iotdb/cluster/client/ClientPoolFactory.java
index 0887992..dfd3283 100644
--- 
a/cluster/src/main/java/org/apache/iotdb/cluster/client/ClientPoolFactory.java
+++ 
b/cluster/src/main/java/org/apache/iotdb/cluster/client/ClientPoolFactory.java
@@ -54,6 +54,7 @@ public class ClientPoolFactory {
             : new TBinaryProtocol.Factory();
     poolConfig = new GenericKeyedObjectPoolConfig();
     poolConfig.setMaxTotalPerKey(maxConnectionForEachNode);
+    poolConfig.setMaxIdlePerKey(maxConnectionForEachNode / 2);
     poolConfig.setMaxWait(Duration.ofMillis(waitClientTimeoutMS));
     poolConfig.setTestOnReturn(true);
     poolConfig.setTestOnBorrow(true);
diff --git 
a/cluster/src/test/java/org/apache/iotdb/cluster/client/ClientPoolFactoryTest.java
 
b/cluster/src/test/java/org/apache/iotdb/cluster/client/ClientPoolFactoryTest.java
index f1e313e..715ebfa 100644
--- 
a/cluster/src/test/java/org/apache/iotdb/cluster/client/ClientPoolFactoryTest.java
+++ 
b/cluster/src/test/java/org/apache/iotdb/cluster/client/ClientPoolFactoryTest.java
@@ -130,6 +130,38 @@ public class ClientPoolFactoryTest {
   }
 
   @Test
+  public void poolIdleObjectEvictionTest() throws Exception {
+    GenericKeyedObjectPool<Node, RaftService.AsyncClient> pool =
+        clientPoolFactory.createAsyncDataPool(ClientCategory.DATA);
+
+    int oldMaxTotalPerKey = pool.getMaxTotalPerKey();
+    pool.setMaxTotalPerKey(2 * pool.getMaxIdlePerKey());
+
+    Node node = constructDefaultNode();
+    List<RaftService.AsyncClient> clientList = new ArrayList<>();
+    for (int i = 0; i < pool.getMaxTotalPerKey(); i++) {
+      RaftService.AsyncClient client = pool.borrowObject(node);
+      Assert.assertNotNull(client);
+      clientList.add(client);
+    }
+
+    for (RaftService.AsyncClient client : clientList) {
+      pool.returnObject(node, client);
+    }
+
+    Assert.assertEquals(0, pool.getNumActive(node));
+    Assert.assertEquals(pool.getMaxIdlePerKey(), pool.getNumIdle(node));
+
+    for (int i = 0; i < pool.getMaxIdlePerKey(); i++) {
+      RaftService.AsyncClient client = pool.borrowObject(node);
+      Assert.assertNotNull(client);
+      Assert.assertTrue(clientList.contains(client));
+    }
+
+    pool.setMaxTotalPerKey(oldMaxTotalPerKey);
+  }
+
+  @Test
   public void createAsyncDataClientTest() throws Exception {
     GenericKeyedObjectPool<Node, RaftService.AsyncClient> pool =
         clientPoolFactory.createAsyncDataPool(ClientCategory.DATA);

Reply via email to