Repository navigation
Commit 41f0a2e
authored
feat(grpc-gcp): move scale-up to background worker (#14206)
With dynamic scaling enabled, **maybeDynamicUpscale()** ran
synchronously on the caller thread during channel selection, before the
stream was counted. It scaled on the pool-wide average only, one channel
per trigger, with no cooldown — so a burst could add channels one RPC at
a time while the caller waited on channel construction, and a single hot
channel never triggered growth if the average stayed low.
**Change**
- Signal after accounting. **activeStreamsCountIncr()** evaluates the
trigger once the stream is reserved: the selected channel above
maxRpcPerChannel, or the pool average above it, signals scale-up.
Channel selection itself no longer scales.
- Single background worker. A one-slot signal (AtomicBoolean
pending/running) coalesces bursts; the worker runs on the shared
background executor, loops while signals arrive, and catches
**Throwable** so one failure can't stop future scale-ups. The scale-down
timer body gets the same guard.
- Bounded, load-sized growth. Desired size = **ceil(totalActiveStreams /
midpoint(minRpc, maxRpc))**, added channels capped at
**maxScaleUpPercent** of the active pool (floor 2) and by maxSize. A
scaleUpCooldown (default 10s) is claimed before channel construction so
signals arriving mid-build are throttled. READY channels awaiting
shutdown are reused before new ones are built.
- Construction outside the lock. Delegate channels are built without
holding the pool monitor; publication rechecks shutdown and headroom
under the lock and closes surplus channels.
- Inactive channels excluded from round-robin, fallback, extrema
(getMin/MaxActiveStreams) and picker scans; the legacy watermark
scale-up no longer computes getMaxActiveStreams() on the hot path when
dynamic scaling is enabled.
- Shutdown ordering: shuttingDown is set under the pool lock as the
first step of shutdown()/shutdownNow(), so a channel cannot be published
after shutdown begins. removedChannelRefs is now a concurrent set, safe
for the worker and the unsynchronized readers (isShutdown, isTerminated,
awaitTermination, stats logging).1 parent d7e2be2 commit 41f0a2e
7 files changed
Lines changed: 912 additions & 86 deletions
File tree
- grpc-gcp-java/src
- main/java/com/google/cloud/grpc
- test/java/com/google/cloud/grpc
0 commit comments