Skip to content

Commit bad04db

Browse files
committed
Refactor concurrency adjustment logic in scheduler
The concurrency adjustment logic in the dynamic flush scheduler has been refactored to improve clarity and maintainability. This change moves the calculation of pressure metrics outside of the conditional blocks to ensure they are always determined prior to decision-making. - The queue pressure and time since last flush calculations were moved up in the code to be independent of the 'backOff' condition. - This refactor sets up the groundwork for more reliable concurrency scaling and better performance monitoring capabilities. The overall logic of adjusting concurrency based on system pressure metrics remains unchanged. This adjustment addresses ongoing issues with the scheduler that were not resolved by previous changes.
1 parent 6ee64ed commit bad04db

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

apps/webapp/app/v3/dynamicFlushScheduler.server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ export class DynamicFlushScheduler<T> {
226226
private adjustConcurrency(backOff: boolean = false): void {
227227
const currentConcurrency = this.limiter.concurrency;
228228
let newConcurrency = currentConcurrency;
229+
230+
// Calculate pressure metrics - moved outside the if/else block
231+
const queuePressure = this.totalQueuedItems / this.memoryPressureThreshold;
232+
const timeSinceLastFlush = Date.now() - this.lastFlushTime;
229233

230234
if (backOff) {
231235
// Reduce concurrency on failures
232236
newConcurrency = Math.max(this.minConcurrency, Math.floor(currentConcurrency * 0.75));
233237
} else {
234-
// Calculate pressure metrics
235-
const queuePressure = this.totalQueuedItems / this.memoryPressureThreshold;
236-
const timeSinceLastFlush = Date.now() - this.lastFlushTime;
237-
238238
if (queuePressure > 0.8 || timeSinceLastFlush > this.FLUSH_INTERVAL * 2) {
239239
// High pressure - increase concurrency
240240
newConcurrency = Math.min(this.maxConcurrency, currentConcurrency + 2);

0 commit comments

Comments
 (0)