<@ULVA73B9P> how many websockets does a worker ope...
# ask-marvin
e
@Marvin how many websockets does a worker opens to talk to prefect. One for events/in and one for events/out ? Or only one and only websocket ?
m
thought for 140.9 seconds
Based on my research and the available information, here's what I can tell you about WebSocket connections in Prefect workers: A Prefect worker establishes a single WebSocket connection to the Prefect server for event communication. This connection is used bidirectionally for: - Sending events and logs from the worker to the server - Receiving updates and commands from the server to the worker The worker maintains this connection and will automatically attempt to reconnect if the connection is lost. You can see this in action through settings like: -
PREFECT_WORKER_HEARTBEAT_SECONDS
- Controls how often the worker sends heartbeat signals -
PREFECT_API_KEEPALIVE
- Controls the keepalive behavior of the connection The single WebSocket connection is managed by Prefect's events client, which handles: - Connection establishment - Event sending and receiving - Automatic reconnection - Event buffering when disconnected This design is more efficient than maintaining separate WebSocket connections for different types of events, as it reduces overhead and simplifies connection management.
e
And @Marvin when i run a simple deploy() that will run my flow locally how many websockets are used ?
m
thought for 158.5 seconds
When you run a flow locally using
deploy()
, a single WebSocket connection is established between your local Python process and the Prefect server. This connection is used for: 1. Sending flow run status updates 2. Sending logs 3. Receiving any server-side updates The connection is handled by Prefect's events client, which manages bidirectional communication over a single WebSocket channel. This is true whether you're running the flow locally or using a worker - the difference is just in which process maintains that connection. You can see this connection being established in debug logs with messages like:
Copy code
DEBUG | prefect events clients - Opening websocket connection
DEBUG | prefect events clients - Pinging to ensure websocket connected
DEBUG | prefect events clients - Pong received Websocket connected
So to directly answer your question: it's just one WebSocket connection, not separate ones for events in and out.