Hi all,

I'd like to propose adding two optional parameters, coreSize and 
maxIdleTimeInMs, to the Java SessionPool (tree model) and TableSessionPool 
(table model).


Background:


SessionPool and TableSessionPool only expose maxSize today. Sessions are 
created on demand and are never evicted. Once a traffic burst pushes the pool 
to maxSize, the client keeps that many long-lived connections to DataNodes 
forever, even after the load drops. For long-running integrations such as 
Flink/Trino connectors, import/export tools and resident collection services, 
idle connections keep consuming client memory and DataNode connection/thread 
resources. Deploying many such instances makes the waste worse.


Proposal:
Two new builder parameters:


  coreSize Minimum number of sessions kept in the pool; idle eviction never 
takes the pool below this value. Default 0. Must be within [0, maxSize].


  maxIdleTimeInMs Maximum time in milliseconds an idle session may stay in the 
pool; sessions idle longer are closed by a background task. Default 0, which 
disables eviction and keeps the current behavior unchanged.


With these, the pool can still expand to maxSize under load and shrinks back to 
coreSize after the load drops.


Example:
  SessionPool pool =
      new SessionPool.Builder()
          .host("127.0.0.1").port(6667).user("root").password("root")
          .maxSize(20)
          .coreSize(5) // keep at least 5 sessions
          .maxIdleTimeInMs(10 * 60 * 1000L) // evict sessions idle over 10 
minutes
          .build();


TableSessionPoolBuilder gets the same two methods.


Implementation notes:
- Idle queue elements carry a return timestamp. Eviction scans the LIFO idle 
queue from the oldest end and stops at the first non-expired entry.
- Eviction reuses the pool's existing single-thread scheduler and runs 
periodically at max(1s, min(maxIdleTime, 60s)). The session count is updated 
under the pool lock; evicted sessions are closed outside the lock.
- Illegal values (coreSize outside [0, maxSize], negative maxIdleTimeInMs) are 
rejected with IllegalArgumentException at construction time.
- Pure client-side change: no RPC, protocol or server changes. Defaults (0/0) 
keep existing behavior, so the API is purely additive and backward compatible.


Thanks,
Weihao Li

Reply via email to