Repository navigation
Conversation
|
We ran into the same problem independently and can confirm this fix. One thing it leaves, which you may want to add: the backing array still grows by one slot per dispatched query for as long as the pool stays saturated. Here's a rotation that models dispatch with every connection busy (
With this PR alone, a pool that stays saturated for hours keeps growing its } else {
xs[index - 1] = undefined
+ if (index > 64 && index * 2 > xs.length) {
+ xs = xs.slice(index)
+ index = 0
+ }
}It composes with your change. End to end (Node 24, PostgreSQL 14, |
Fix queue removal scanning already-consumed entries
Summary
Start
Queue.remove()searches at the queue's read index instead of the beginning of its backing array:shift()leaves cleared slots behind until the queue drains. During connection-pool scheduling,move()can callremove()for a connection already taken byshift(), causing a failed search through the entire backing array. As the consumed prefix grows, searches become more expensive even when few connections remain active.Searching from the read index skips that prefix, reducing failed searches from O(backing-array length) to O(active-queue length). The public API and FIFO order are unchanged. This does not compact the array or eliminate redundant removal calls.
Benchmark
Postgres.js 3.4.9 on Deno 2.9.7, using 4 connections,
prepare: false, defaultmax_pipeline(100), andselect 1 as x. Concurrency increases through the stages below, each lasting 8 seconds, with no warmup.Throughput improves by 2.28–12.63x at concurrency 50–300 in this run. At concurrency 400 and 500, QPS is 1.84% and 3.63% lower, respectively. Both runs reported zero failed or dropped queries.
CPU is client-process user + system CPU time, including the load generator; 100% represents one logical core. This is not an across-the-board CPU reduction.
These results are one before/after pair with no warmup. Stages share a process and pool, so they are not independent steady-state measurements. Repeated runs are needed to establish reproducibility.