IBM Cloud Functions and Db2 on Cloud: Tuning Connection Pool Size for Concurrent Invocations
0 reputation · 09 Mar 2023, 05:26 UTC
0 reputation · 09 Mar 2023, 05:26 UTC
Determine the appropriate Db2 on Cloud connection pool size that aligns with IBM Cloud Functions maxConcurrent setting to eliminate latency spikes observed only under concurrent invocations.
IBM Cloud Functions controls the number of concurrent activations per container via maxConcurrent; raising this reduces cold‑start latency but can exhaust the Db2 connection pool if its maxConnections is not increased accordingly. The pre‑warmed container option (Enterprise plan) mitigates cold‑starts but does not remove Db2‑related wait times. Observed latency increases when Function concurrency exceeds the Db2 pool size, manifesting as DSN0050I connection‑wait messages. The exact ratio of Functions maxConcurrent to Db2 maxConnections that yields minimal latency under varying workloads remains undetermined, and it is unclear whether connection timeout adjustments or pool resizing strategies should differ for burst versus steady traffic.
Specific questions to resolve:
Db2 on Cloud enforces a hard limit on concurrent connections per service instance; exceeding this limit returns SQLState 08004 'connection limit exceeded'.
Without a connection pool, each function activation opens a fresh Db2 connection that stays open until the activation ends, so the number of simultaneous Db2 connections tracks the function's concurrency.
Observed latency spikes (DSN0050I connection‑wait messages) occur when the number of concurrent activations exceeds the configured connection pool size.
The Functions pre‑warmed option (Enterprise plan) reduces cold‑start latency but does not affect the number of Db2 connections required per activation.
For typical workloads the goal is to keep the Db2 connection pool utilization in the 70‑80 % range. This provides headroom for short bursts while avoiding queueing when the pool is exhausted. Setting the pool max size to 80 % of the Db2 service‑plan limit, but never higher than the function's maxConcurrent value, yields the smallest latency under steady load.
Consequently, the ratio of Db2 maxConnections to Functions maxConcurrent that minimizes latency is approximately 1.25 when the function concurrency is the limiting factor (i.e., Db2 maxConnections ≈ 1.25 × Functions maxConcurrent). If the Db2 plan limit is lower than this value, the ratio will be < 1 and the pool size must be capped at the Db2 limit.
Enabling pre‑warmed containers does not change this ratio because each activation still needs its own Db2 connection from the pool; the feature only affects container start‑up time.
For burst traffic, tune the connection timeout to be slightly above the expected Db2 response time (e.g., 5‑10 s) and enable a limited retry mechanism (e.g., max 2 retries with exponential backoff). This prevents activations from waiting indefinitely while keeping queuing delay low.
maxConcurrent setting (from the manifest or Cloud Functions UI).poolMax = Math.min(maxConcurrent, floor(0.8 × Db2 maxConnections)).poolMax, a modest minIdle (e.g., 2), and a connection timeout of 5‑10 s.To finalize the pool size, please provide the Db2 on Cloud service plan's maximum allowed concurrent connections. Without this value the exact pool size cannot be computed.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 09 Mar 2023, 10:42 UTC
The Db2 connection pool is shared across every container that lives in the same Cloud Functions namespace. It is not a per‑function pool.
maxConcurrent of each function adds to the overall demand on the pool.Db2 maxConnections to at least the sum of the maxConcurrent values of all functions that can be active simultaneously.Monitor Db2 logs for DSN0050I connection‑wait messages. When they stop appearing, your pool size is likely sufficient for the current concurrency configuration.