Skip to content

v3: prevent envs with excess queues from degrading dequeue performance #1982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2025
Merged
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
1 change: 1 addition & 0 deletions apps/webapp/app/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ const EnvironmentSchema = z.object({
.int()
.default(60 * 1000 * 15),
MARQS_SHARED_QUEUE_LIMIT: z.coerce.number().int().default(1000),
MARQS_MAXIMUM_QUEUE_PER_ENV_COUNT: z.coerce.number().int().default(50),
MARQS_DEV_QUEUE_LIMIT: z.coerce.number().int().default(1000),
MARQS_MAXIMUM_NACK_COUNT: z.coerce.number().int().default(64),
MARQS_CONCURRENCY_LIMIT_BIAS: z.coerce.number().default(0.75),
Expand Down
21 changes: 17 additions & 4 deletions apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export type FairDequeuingStrategyOptions = {
biases?: FairDequeuingStrategyBiases;
reuseSnapshotCount?: number;
maximumEnvCount?: number;
/**
* Maximum number of queues to process per environment
* If not provided, all queues in an environment will be processed
*/
maximumQueuePerEnvCount?: number;
};

type FairQueueConcurrency = {
Expand Down Expand Up @@ -216,8 +221,6 @@ export class FairDequeuingStrategy implements MarQSFairDequeueStrategy {
return result;
}

// Helper method to maintain DRY principle
// Update return type
#orderQueuesByEnvs(envs: string[], snapshot: FairQueueSnapshot): Array<EnvQueues> {
const queuesByEnv = snapshot.queues.reduce((acc, queue) => {
if (!acc[queue.env]) {
Expand All @@ -231,11 +234,17 @@ export class FairDequeuingStrategy implements MarQSFairDequeueStrategy {
if (queuesByEnv[envId]) {
// Get ordered queues for this env
const orderedQueues = this.#weightedRandomQueueOrder(queuesByEnv[envId]);

// Apply queue limit if maximumQueuePerEnvCount is set
const limitedQueues = this.options.maximumQueuePerEnvCount
? orderedQueues.slice(0, this.options.maximumQueuePerEnvCount)
: orderedQueues;

// Only add the env if it has queues
if (orderedQueues.length > 0) {
if (limitedQueues.length > 0) {
acc.push({
envId,
queues: orderedQueues.map((queue) => queue.id),
queues: limitedQueues.map((queue) => queue.id),
});
}
}
Expand Down Expand Up @@ -512,6 +521,10 @@ export class FairDequeuingStrategy implements MarQSFairDequeueStrategy {

span.setAttribute("queue_count", result.length);

if (result.length === this.options.parentQueueLimit) {
span.setAttribute("parent_queue_limit_reached", true);
}

return result;
});
}
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/app/v3/marqs/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,7 @@ function getMarQSClient() {
},
reuseSnapshotCount: env.MARQS_REUSE_SNAPSHOT_COUNT,
maximumEnvCount: env.MARQS_MAXIMUM_ENV_COUNT,
maximumQueuePerEnvCount: env.MARQS_MAXIMUM_QUEUE_PER_ENV_COUNT,
}),
envQueuePriorityStrategy: new FairDequeuingStrategy({
tracer: tracer,
Expand Down
Loading
Loading