feat(server-core): bound refresh-key dispatch fan-out by concurrency per orchestrator id#11106
Draft
paveltiunov wants to merge 1 commit into
Draft
feat(server-core): bound refresh-key dispatch fan-out by concurrency per orchestrator id#11106paveltiunov wants to merge 1 commit into
paveltiunov wants to merge 1 commit into
Conversation
…per orchestrator id Co-authored-by: Pavel Tiunov <pavel.tiunov@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #11106 +/- ##
===========================================
- Coverage 83.61% 58.53% -25.09%
===========================================
Files 256 216 -40
Lines 78904 17284 -61620
Branches 0 3525 +3525
===========================================
- Hits 65975 10117 -55858
+ Misses 12929 6652 -6277
- Partials 0 515 +515
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The scheduled refresh dispatches all refresh-key queries simultaneously with no concurrency cap at the dispatch level.
RefreshScheduler.refreshCubesRefreshKeyfans out with nestedPromise.all— over cubes, and within each cube over timezones — without anypLimitor throttle. Theconcurrency/workerIndicesinScheduledRefreshQueryingOptionswere only consumed byrefreshPreAggregations(the round-robin worker iterator), not byrefreshCubesRefreshKey.While the database is still effectively bounded downstream (per-datasource
QueryQueueconcurrency,@AsyncDebounce()onloadRefreshKey, and renewal-threshold/in-memory caching), the dispatch itself creates a large promise fan-out in Node for deployments with many cubes/timezones — i.e. memory and event-loop pressure.This PR adds a
pLimitinrefreshCubesRefreshKeyto bound the dispatch fan-out, using the scheduler concurrency (which is derived per orchestrator from the minimum queue concurrency). The limiter is shared per orchestrator id, so concurrent scheduled refresh runs that resolve to the same orchestrator (e.g. multiple security contexts) respect a single cap rather than each flooding the event loop independently.Changes
server.ts: addgetRefreshKeysLimiter(context, concurrency)which returns apLimitinstance cached per orchestrator id (rebuilt only when the concurrency value changes). The cache lives on the long-livedCubejsServerCoreso it persists across short-livedRefreshSchedulerinstances.RefreshScheduler.ts: wrap each refresh-keyexecuteQuerydispatch (and itsgetSql) in the shared limiter so no more thanconcurrencyrefresh-key queries are dispatched at once per orchestrator.Tests
getRefreshKeysLimiter returns a shared limiter per orchestrator id— verifies the limiter is reused for the same orchestrator id + concurrency and rebuilt when concurrency changes.Refresh key dispatch is bounded by concurrency— instruments the orchestrator'sexecuteQueryto track in-flightloadRefreshKeysOnlydispatches across multiple cubes/timezones and asserts the peak concurrency never exceeds the configured value.All 15 tests in
RefreshScheduler.test.tspass;tscbuild and ESLint are clean.