Summary:
This revision introduces a multi route (user-database) connection pooling solution which aims at providing a fair allocation of physical connections across different user-database pairs dynamically based on demand.
#### Algorithm
The connection manager maintains the following information for every route:
`od_server_pool_total(route->server_pool)`: stores the number of physical connections in the pool for the route.
`yb_od_client_pool_queue(&route->client_pool)`: stores the number of requests for the route waiting for a free physical connection.
Define:
num_active_routes: Number of unique routes with non-zero values of `yb_od_client_pool_queue(&route->client_pool) + od_server_pool_total(route->server_pool)`
per_route_quota: This is the guideline quota for each route, and is a dynamic value. It is computed as max_connections / num_active_routes at any given time.
num_all_physical_connections: The total number of all physical connections that exists. This is the sum of values of in_use for all routes.
##### Algorithm - Attach
Attach is the stage when a logical connection is attached to a physical connection in the connection manager. The algorithm for attach is as follows:
1. If an idle physical connection is available for the route: attach to it, otherwise step 2
2. If num_all_physical_connections < max_connections: start a new physical connection for the route. Basically, if the demand is less from other routes for connections, then another route is allowed to burst above its quota all the way till max_connections
3. Otherwise i.e. num_all_physical_connections = max_connections:
- If an idle connection of a different route r which has `od_server_pool_total(r->server_pool) > per_route_quota` and has an idle connection
- Close the idle connection in r
- Start a physical connection for the route
- Else: We have to wait for a slot to become available
- Wait and retry
##### Algorithm - Detach
Detach is the stage when a logical connection becomes IDLE (say after transaction commit) and is detached from the physical connection. This physical connection is then returned to the pool to be used by another logical connection if needed.
The algorithm for detach is as it was before. We rely on the attach algorithm to close the connections of other routes when unable to meet the demands.
Jira: DB-14484
Test Plan: Jenkins: enable connection manager, all tests
Reviewers: devansh.saxena, rbarigidad, vpatibandla, skumar, mkumar
Reviewed By: devansh.saxena
Subscribers: yql
Differential Revision: https://phorge.dev.yugabyte.com/D40352