Skip to content

Conversation

Cat-Drink
Copy link

@Cat-Drink Cat-Drink commented Sep 15, 2025

Purpose of the pull request

This pull request introduces support for the Kubernetes client connection pool, optimizing the interaction performance and resource management between Apache DolphinScheduler and Kubernetes clusters. By maintaining a reuse mechanism for client connections, this feature significantly reduces the overhead caused by frequent creation and destruction of Kubernetes clients, thereby improving the overall efficiency and stability of the system.

Brief change log

  • Core Backend Implementation: Added the KubernetesClientPool class, which implements a singleton-pattern connection pool manager to maintain an independent connection pool for each Kubernetes cluster.
  • Connection Pool Configuration: Implemented the PoolConfig inner class, which supports configuration items such as minimum idle connections, maximum idle connections, maximum connections, maximum waiting time, and idle timeout. These configurations can be customized through properties in TaskConstants.
  • Cluster Connection Pool: Implemented the ClusterClientPool inner class, which is responsible for managing client connections of specific clusters, including the creation, acquisition, return, and closure of connections.
  • Idle Connection Cleanup: Added a periodic cleanup thread that executes the cleanupIdleClients method every 30 seconds to clear timed-out idle connections, effectively saving resources.
  • Cluster Identification: Implemented a cluster identification generation mechanism based on kubeconfig, using the SHA-256 algorithm to generate a unique identifier for each cluster.
  • Client Validation: Added the isClientValid method to ensure that the returned client connection remains valid.
  • Integration into Utility Classes: Updated utility classes such as K8sUtils and KubernetesApplicationManager to enable them to acquire and return clients using the connection pool.

Verify this pull request

This change includes comprehensive test cases and can be verified through the following methods:

Automated Testing

  • Basic Functionality Test: KubernetesClientPoolTest.testKubernetesClientPoolBasicFunction verifies the basic operations of the connection pool (acquiring cluster ID, obtaining client, returning client, and closing the connection pool).
  • Configuration Test: KubernetesClientPoolTest.testKubernetesClientPoolConfig verifies the correctness of connection pool configurations.
  • Cluster ID Generation Test: KubernetesClientPoolTest.testClusterIdGeneration verifies the function of generating a unique cluster identifier based on kubeconfig.
  • Singleton Pattern Test: KubernetesClientPoolTest.testSingletonPattern verifies the singleton pattern implementation of the connection pool.
  • Concurrent Access Test: Verifies the thread safety and stability of the connection pool in a multi-threaded environment.
  • Timeout Handling Test: KubernetesClientPoolTest.testClusterClientPoolBorrowObjectTimeout verifies the handling mechanism for client acquisition timeouts.
  • Idle Connection Cleanup Test: KubernetesClientPoolTest.testCleanupIdleClients and KubernetesClientPoolTest.testClusterClientPoolCleanupIdle verify the periodic cleanup function of idle connections.

Manual Verification Steps

  1. Ensure that appropriate connection pool parameters (such as k8s.client.pool.max.size) are set in the configuration file.
  2. Submit multiple Kubernetes tasks to different clusters.
  3. Check the logs to verify whether the connection pool correctly creates and manages client connections.
  4. Monitor system resource usage to verify whether the connection pool effectively reduces the overhead caused by connection creation and destruction.

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

Copy link

boring-cyborg bot commented Sep 15, 2025

Thanks for opening this pull request! Please check out our contributing guidelines. (https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)

@github-actions github-actions bot added UI ui and front end related backend test labels Sep 15, 2025
@Cat-Drink Cat-Drink changed the title K8s Connections Pool [Feature-3328][Task] Kubernetes Connection Pool Implementation Sep 15, 2025
@wangxj3 wangxj3 changed the title [Feature-3328][Task] Kubernetes Connection Pool Implementation [DSIP-88][Task] Kubernetes Connection Pool Implementation Sep 16, 2025
Copy link
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr's title and DSIP-88 are no related. Please modify the correct title and with full design detail and description. @Cat-Drink

Copy link

@wangxj3 wangxj3 changed the title [DSIP-88][Task] Kubernetes Connection Pool Implementation [Feature-88][SERVER] Kubernetes Connection Pool Implementation Oct 14, 2025
@wangxj3 wangxj3 changed the title [Feature-88][SERVER] Kubernetes Connection Pool Implementation [Improvement-88][SERVER] Improvement Kubernetes Connection Pool Implementation Oct 14, 2025
@wangxj3 wangxj3 changed the title [Improvement-88][SERVER] Improvement Kubernetes Connection Pool Implementation [Improvement-88][SERVER] Kubernetes Connection Pool Implementation Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants