Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions packages/cubejs-cubestore-driver/src/CubeStoreQueueDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,31 @@ class CubestoreQueueDriverConnection implements QueueDriverConnectionInterface {
}

public async getActiveAndToProcess(): Promise<GetActiveAndToProcessResponse> {
const active: QueryKeysTuple[] = [];
const toProcess: QueryKeysTuple[] = [];

const rows = await this.driver.query<CubeStoreListResponse>('QUEUE LIST ?', [
this.options.redisQueuePrefix
]);
if (rows.length) {
for (const row of rows) {
if (row.status === 'active') {
active.push([
row.id as QueryKeyHash,
row.queue_id ? parseInt(row.queue_id, 10) : null,
]);
} else {
toProcess.push([
row.id as QueryKeyHash,
row.queue_id ? parseInt(row.queue_id, 10) : null,
]);
}
}
}

return [
// We don't return active queries, because it's useless
// There is only one place where it's used, and it's QueryQueue.reconcileQueueImpl
// Cube Store provides strict guarantees that queue item cannot be active & pending in the same time
[],
await this.getToProcessQueries()
active,
toProcess,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,16 @@ export class QueryQueue {
}
}));

const [_active, toProcess] = await queueConnection.getActiveAndToProcess();
const [active, toProcess] = await queueConnection.getActiveAndToProcess();

/**
* Important notice: Concurrency configuration works per a specific queue, not per node.
*
* In production clusters where it contains N nodes, it shares the same concurrency. It leads to a point
* where every node tries to pick up jobs as much as concurrency is defined for the whole cluster. To minimize
* the effect of competition between nodes, it's important to reduce the number of tries to process by active jobs.
*/
const toProcessLimit = active.length >= this.concurrency ? 1 : this.concurrency - active.length;

const tasks = toProcess
.filter(([queryKey, _queueId]) => {
Expand All @@ -559,7 +568,7 @@ export class QueryQueue {
return false;
}
})
.slice(0, this.concurrency)
.slice(0, toProcessLimit)
.map(([queryKey, queueId]) => this.sendProcessMessageFn(queryKey, queueId));

await Promise.all(tasks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export function QueryQueueBenchmark(name: string, options: QueryQueueTestOptions
} else {
counters.events[event] = 1;
}

if (event.includes('error')) {
console.log(event, _params);
}
},
queueDriverFactory,
...options
Expand All @@ -159,7 +163,8 @@ export function QueryQueueBenchmark(name: string, options: QueryQueueTestOptions
const progressIntervalId = setInterval(() => {
console.log('running', {
...counters,
processingPromisses: processingPromisses.length
processingPromisses: processingPromisses.length,
benchSettings,
});
}, 1000);

Expand All @@ -177,18 +182,25 @@ export function QueryQueueBenchmark(name: string, options: QueryQueueTestOptions

const queueId = crypto.randomBytes(12).toString('hex');
const running = (async () => {
await queue.executeInQueue('query', queueId, {
// eslint-disable-next-line no-bitwise
payload: 'a'.repeat(benchSettings.queuePayloadSize)
}, 1, {
try {
await queue.executeInQueue('query', queueId, {
// eslint-disable-next-line no-bitwise
payload: {
large_str: 'a'.repeat(benchSettings.queuePayloadSize)
},
orphanedTimeout: 120
}, 1, {
stageQueryKey: 1,
requestId: 'request-id',
spanId: 'span-id'
});
});
} catch (e) {
console.error(e);
}

counters.queueResolved++;

// loosing memory for result
// losing memory for a result
return null;
})();

Expand Down
Loading