Skip to content

Commit 92f933f

Browse files
0skiTrigger.dev RepoOps
authored andcommitted
fix(redis-worker): pop ready worker queue messages without opening a new connection
Batch items are processed faster when the batch queue has a backlog. Worker queue consumers used to open a new Redis connection for every message they popped, even when messages were already waiting. They now take a ready message on the existing connection and only open a dedicated blocking connection when the queue is empty, which removes several round trips per batch item and most of the Redis CPU spent on connection setup. Mono-RevId: 7a492d821fc4bdcc212cf08bc1ddd67fa6a8517a
1 parent 1fc1c58 commit 92f933f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎packages/redis-worker/src/fair-queue/workerQueue.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ export class WorkerQueueManager {
9797
): Promise<string | null> {
9898
const workerQueueKey = this.keys.workerQueueKey(workerQueueId);
9999

100+
if (signal?.aborted) {
101+
return null;
102+
}
103+
104+
// Fast path: under load the queue is rarely empty, so pop on the shared connection
105+
// and only pay for a dedicated blocking connection when there is nothing to take
106+
const readyMessageKey = await this.redis.lpop(workerQueueKey);
107+
if (readyMessageKey) {
108+
return readyMessageKey;
109+
}
110+
100111
// Create a separate client for blocking operation
101112
// This is required because BLPOP blocks the connection
102113
const blockingClient = this.redis.duplicate();

0 commit comments

Comments
 (0)