Skip to content

Commit 4ae21fa

Browse files
committed
fix: Reuse queries cache in refresh worker pre-aggregation iterator to reduce memory usage in high concurrency environment
1 parent 67221af commit 4ae21fa

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

packages/cubejs-server-core/src/core/RefreshScheduler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export class RefreshScheduler {
461461
}));
462462
}
463463

464-
protected async roundRobinRefreshPreAggregationsQueryIterator(context, compilerApi: CompilerApi, queryingOptions) {
464+
protected async roundRobinRefreshPreAggregationsQueryIterator(context, compilerApi: CompilerApi, queryingOptions, queriesCache: { [key: string]: Promise<PreAggregationDescription[][]> }) {
465465
const { timezones, preAggregationsWarmup } = queryingOptions;
466466
const scheduledPreAggregations = await compilerApi.scheduledPreAggregations();
467467

@@ -470,7 +470,6 @@ export class RefreshScheduler {
470470
let partitionCursor = 0;
471471
let partitionCounter = 0;
472472

473-
const queriesCache: { [key: string]: Promise<PreAggregationDescription[][]> } = {};
474473
const finishedPartitions = {};
475474
scheduledPreAggregations.forEach((p, pi) => {
476475
timezones.forEach((t, ti) => {
@@ -579,13 +578,14 @@ export class RefreshScheduler {
579578
const { queryIteratorState, concurrency, workerIndices } = queryingOptions;
580579

581580
const preAggregationsLoadCacheByDataSource = {};
581+
const queriesCache: { [key: string]: Promise<PreAggregationDescription[][]> } = {};
582582
return Promise.all(R.range(0, concurrency)
583583
.filter(workerIndex => workerIndices.indexOf(workerIndex) !== -1)
584584
.map(async workerIndex => {
585585
const queryIteratorStateKey = JSON.stringify({ ...securityContext, workerIndex });
586586
const queryIterator = queryIteratorState && queryIteratorState[queryIteratorStateKey] ||
587587
(await this.roundRobinRefreshPreAggregationsQueryIterator(
588-
context, compilerApi, queryingOptions
588+
context, compilerApi, queryingOptions, queriesCache
589589
));
590590
if (queryIteratorState) {
591591
queryIteratorState[queryIteratorStateKey] = queryIterator;

rust/cubestore/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
"allowSyntheticDefaultImports": true,
2323
"skipLibCheck": true,
2424
"forceConsistentCasingInFileNames": true
25-
}
25+
},
26+
"exclude": ["target", "dist", "node_modules"]
2627
}

0 commit comments

Comments
 (0)