From d9273f27ae8df6c41e56a8258f540a4ffd9a7b7b Mon Sep 17 00:00:00 2001 From: aoife cassidy Date: Mon, 4 Nov 2024 20:04:59 +0200 Subject: [PATCH] fix(worker): make numIdleProcesses work (#135) --- .changeset/afraid-camels-push.md | 5 +++++ agents/package.json | 2 +- agents/src/ipc/proc_pool.ts | 8 ++++---- pnpm-lock.yaml | 12 ++++++------ 4 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 .changeset/afraid-camels-push.md diff --git a/.changeset/afraid-camels-push.md b/.changeset/afraid-camels-push.md new file mode 100644 index 0000000..397696a --- /dev/null +++ b/.changeset/afraid-camels-push.md @@ -0,0 +1,5 @@ +--- +"@livekit/agents": patch +--- + +make numIdleProcesses work diff --git a/agents/package.json b/agents/package.json index 8c3a33b..95ad84a 100644 --- a/agents/package.json +++ b/agents/package.json @@ -21,7 +21,7 @@ "typescript": "^5.0.0" }, "dependencies": { - "@livekit/mutex": "^1.0.0", + "@livekit/mutex": "^1.1.0", "@livekit/protocol": "^1.21.0", "@livekit/rtc-node": "^0.11.0", "commander": "^12.0.0", diff --git a/agents/src/ipc/proc_pool.ts b/agents/src/ipc/proc_pool.ts index d6492d6..5f2a3f0 100644 --- a/agents/src/ipc/proc_pool.ts +++ b/agents/src/ipc/proc_pool.ts @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2024 LiveKit, Inc. // // SPDX-License-Identifier: Apache-2.0 -import { Mutex } from '@livekit/mutex'; +import { MultiMutex, Mutex } from '@livekit/mutex'; import type { RunningJobInfo } from '../job.js'; import { Queue } from '../utils.js'; import type { JobExecutor } from './job_executor.js'; @@ -17,18 +17,18 @@ export class ProcPool { closed = false; controller = new AbortController(); initMutex = new Mutex(); - procMutex: Mutex; + procMutex: MultiMutex; procUnlock?: () => void; warmedProcQueue = new Queue(); constructor( agent: string, - _numIdleProcesses: number, + numIdleProcesses: number, initializeTimeout: number, closeTimeout: number, ) { this.agent = agent; - this.procMutex = new Mutex(); + this.procMutex = new MultiMutex(numIdleProcesses); this.initializeTimeout = initializeTimeout; this.closeTimeout = closeTimeout; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a61a3f2..10075d8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -78,8 +78,8 @@ importers: agents: dependencies: '@livekit/mutex': - specifier: ^1.0.0 - version: 1.0.0 + specifier: ^1.1.0 + version: 1.1.0 '@livekit/protocol': specifier: ^1.21.0 version: 1.21.0 @@ -488,8 +488,8 @@ packages: '@livekit/changesets-changelog-github@0.0.4': resolution: {integrity: sha512-MXaiLYwgkYciZb8G2wkVtZ1pJJzZmVx5cM30Q+ClslrIYyAqQhRbPmZDM79/5CGxb1MTemR/tfOM25tgJgAK0g==} - '@livekit/mutex@1.0.0': - resolution: {integrity: sha512-aiUhoThBNF9UyGTxEURFzJLhhPLIVTnQiEVMjRhPnfHNKLfo2JY9xovHKIus7B78UD5hsP6DlgpmAsjrz4U0Iw==} + '@livekit/mutex@1.1.0': + resolution: {integrity: sha512-XRLG+z/0uoyDioupjUiskjI06Y51U/IXVPJn7qJ+R3J75XX01irYVBM9MpxeJahpVoe9QhU4moIEolX+HO9U9g==} '@livekit/protocol@1.21.0': resolution: {integrity: sha512-3TohFPNZy1axTuoDLU6mA1rwuP4VawgehvX52OoLJnU+fNQYfmMJqz8k7NSh79jG5I8Og77YYhT905Omrhli2A==} @@ -3384,7 +3384,7 @@ snapshots: transitivePeerDependencies: - encoding - '@livekit/mutex@1.0.0': {} + '@livekit/mutex@1.1.0': {} '@livekit/protocol@1.21.0': dependencies: @@ -3408,7 +3408,7 @@ snapshots: '@livekit/rtc-node@0.11.0': dependencies: '@bufbuild/protobuf': 2.2.1 - '@livekit/mutex': 1.0.0 + '@livekit/mutex': 1.1.0 '@livekit/typed-emitter': 3.0.0 optionalDependencies: '@livekit/rtc-node-darwin-arm64': 0.11.0