Skip to content

Commit 8771c07

Browse files
committed
perf(run-store,webapp): parallelize idempotency fan-out and cap lookup concurrency
Run the routing store's new and legacy idempotency lookups concurrently to match the existing findRuns fan-out, and cap the per-batch idempotency point-lookup concurrency at 5 to leave headroom in the connection pool.
1 parent 4d8d5ab commit 8771c07

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

apps/webapp/app/v3/services/batchTriggerV3.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { OutOfEntitlementError, TriggerTaskService } from "./triggerTask.server"
3434

3535
const PROCESSING_BATCH_SIZE = 50;
3636
const IDEMPOTENCY_KEY_LOOKUP_CHUNK_SIZE = 50;
37-
const IDEMPOTENCY_KEY_LOOKUP_CONCURRENCY = 10;
37+
const IDEMPOTENCY_KEY_LOOKUP_CONCURRENCY = 5;
3838

3939
function chunkArray<T>(items: T[], size: number): T[][] {
4040
const chunks: T[][] = [];

internal-packages/run-store/src/runOpsStore.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,13 @@ export class RoutingRunStore implements RunStore {
468468
if (args.idempotencyKeys.length === 0) {
469469
return [];
470470
}
471-
const newRows = await this.#new.findRunsByIdempotencyKeys(
472-
args,
473-
RoutingRunStore.#ownPrimary(this.#new, client)
474-
);
475-
const legacyRows = await this.#legacy.findRunsByIdempotencyKeys(
476-
args,
477-
RoutingRunStore.#ownPrimary(this.#legacy, client)
478-
);
471+
const [newRows, legacyRows] = await Promise.all([
472+
this.#new.findRunsByIdempotencyKeys(args, RoutingRunStore.#ownPrimary(this.#new, client)),
473+
this.#legacy.findRunsByIdempotencyKeys(
474+
args,
475+
RoutingRunStore.#ownPrimary(this.#legacy, client)
476+
),
477+
]);
479478
const byKey = new Map<string, IdempotencyKeyRunMatch>();
480479
for (const row of legacyRows) {
481480
if (row.idempotencyKey != null) byKey.set(row.idempotencyKey, row);

0 commit comments

Comments
 (0)