Repository navigation
feat: prewarm the room connection in idle job processes - #8522
Closed
cnderrauber wants to merge 1 commit into
Closed
cnderrauber wants to merge 1 commit into
cnderrauber wants to merge 1 commit into
Conversation
Idle job processes keep a TCP/TLS connection to the LiveKit server open and hand it to JobContext.connect(), so a dispatched job only performs the WebSocket upgrade. - The worker picks the URL to warm: ws_url when self-hosted; on LiveKit Cloud, the /settings/regions entry for the registered region, signed with the worker's API key, re-run on every registration and overridden by the first job_assign.url. - ProcPool sends PrewarmConnectionRequest (IPC msg 13) to idle processes; each keeps one connection, replacing it when older than 60s or closed by the server. - LIVEKIT_PREWARM_CONNECTION=0 disables it. Requires a livekit-rtc release with PrewarmedConnection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on
livekit. Bump thelivekit==pin before merging.CI fails until then: against
livekit1.2.1,RoomOptionshas noprewarmed_connection.Summary
Idle job processes keep a TCP+TLS connection to the LiveKit server open, so when a job is dispatched,
JobContext.connect()only does the WebSocket upgrade.ws_url./settings/regions, signed with the worker's API key, picking the entry forserver_info.region. The firstjob_assign.urloverrides it.ProcPool.set_prewarm_urlsendsPrewarmConnectionRequest(IPC msg 13) to idle processes.JobContext.connect(), which passes it asRoomOptions.prewarmed_connectionand closes it afterwards. If it's dead or for another host, connect dials fresh as before.LIVEKIT_PREWARM_CONNECTION=0disables it.Why
Benchmark (dispatch → agent joined, network conditioner, wss): 631 → 400 ms p50 for connect, 1069 → 836 ms dispatch → joined.
Tests
tests/test_worker.py: region URL selection and Cloud URL detection.tests/test_worker.pyandtests/test_ipc.pypass against the python-sdks and rust-sdks branches above.🤖 Generated with Claude Code