Skip to content

vllm.v1.kv_offload.tiering.p2p.control

Modules:

  • base –

    Abstract base classes for the P2P control-plane transport.

  • zmq –

    ZMQ-based transport layer for P2P KV cache sharing.

Classes:

ControlConnection

Bases: ABC

Bidirectional message channel to a single remote peer.

Lifecycle
  1. Created by ControlTransport (connect() or poll())
  2. Used for send/recv by sessions
  3. Marked dead on disconnect (mark_dead())
  4. Cleaned up with close()

Once mark_dead() is called, alive becomes False and the owning session should stop using this connection. close() releases underlying resources (sockets, monitors).

Methods:

  • close –

    Release all resources (sockets, monitors).

  • mark_dead –

    Mark this connection as dead (peer disconnected).

  • recv –

    Drain and return all messages received since the last call.

  • send –

    Enqueue a message for delivery to the peer.

Attributes:

  • alive (bool) –

    True if the connection is usable. False after mark_dead/close.

alive abstractmethod property

True if the connection is usable. False after mark_dead/close.

close() abstractmethod

Release all resources (sockets, monitors).

Idempotent. After close(), alive returns False.

mark_dead() abstractmethod

Mark this connection as dead (peer disconnected).

After this call, alive returns False. The session should stop using this connection and the transport will clean it up. Resources are not released here — close() must still run.

recv() abstractmethod

Drain and return all messages received since the last call.

Returns an empty sequence if no messages are pending. The returned sequence is read-only — callers must not mutate it. Messages are dicts deserialized from the wire format.

send(msg) abstractmethod

Enqueue a message for delivery to the peer.

Must not block. Serialization happens internally. Raises on closed connection.

ControlTransport

Bases: ABC

Manages peer connections and drives all control-plane I/O.

Owns the listening socket and all active connections. The caller must invoke poll() periodically to process I/O.

Lifecycle
  1. Constructed with a local identity and listen address
  2. connect() to reach remote peers
  3. poll() to accept inbound peers and process messages
  4. close() to shut down

Methods:

  • close –

    Shut down the transport and all connections.

  • connect –

    Create an outbound connection to a remote peer.

  • poll –

    Process all pending I/O and return newly accepted connections.

close() abstractmethod

Shut down the transport and all connections.

Closes the listening socket and all active connections. Idempotent.

connect(peer_id) abstractmethod

Create an outbound connection to a remote peer.

Parameters:

  • peer_id

    (str) –

    Remote peer identity (format: "host:port").

Returns:

The connection's send queue is live immediately — messages sent before the remote peer's poll() will be buffered.

A connection to peer_id that is registered but no longer alive is retired and replaced; a live one is a duplicate and must not be replaced.

poll() abstractmethod

Process all pending I/O and return newly accepted connections.

This is the main I/O driver. Each call: - Receives messages from all connected peers (buffered in each connection's recv() queue) - Accepts new inbound peers and creates connections for them (first message already in recv() buffer) - Detects disconnections and marks connections dead

Returns:

ZmqConnection

Bases: ControlConnection

Bidirectional message channel to a single remote peer.

Methods:

  • enqueue –

    Buffer an incoming message.

  • mark_dead –

    Mark connection as disconnected.

  • recv –

    Drain and return all buffered incoming messages.

  • send –

    Send a msgpack-encoded message to this peer.

Attributes:

  • monitor_socket (Socket) –

    Monitor socket for disconnect detection (used by ZmqTransport).

monitor_socket property

Monitor socket for disconnect detection (used by ZmqTransport).

enqueue(msg)

Buffer an incoming message.

mark_dead()

Mark connection as disconnected.

Only flips liveness: the sockets stay open until close() releases them, so the owner can still drain recv() before tearing down.

recv()

Drain and return all buffered incoming messages.

send(msg)

Send a msgpack-encoded message to this peer.

Never blocks: callers hold the tiering manager lock. Raises ConnectionError once _SNDHWM messages are queued for the peer, so the owning session marks the connection dead instead of stalling.

ZmqTransport

Bases: ControlTransport

ZMQ implementation of ControlTransport.

Manages a ROUTER socket for accepting connections and DEALER sockets for outbound connections. Message-content agnostic.

Methods:

  • connect –

    Open an outbound connection to a remote peer.

  • poll –

    Process all pending I/O. Returns newly accepted connections.

_check_monitors()

Non-blocking: check all monitor sockets for fatal events.

_open_connection(peer_id, direction='outbound')

Create a DEALER socket + monitor and register the connection.

_recv_router()

Non-blocking: receive all pending messages from ROUTER.

_sweep_dead_connections()

Unregister and release every connection that is no longer alive.

connect(peer_id)

Open an outbound connection to a remote peer.

A dead connection can still be registered: its owning session may mark it dead after this tick's sweep already ran, and poll() only unregisters it on the next pass. Retire such an entry instead of asserting, so a reconnect landing in that window succeeds. A live entry is still a genuine duplicate.

poll()

Process all pending I/O. Returns newly accepted connections.

  • Receives messages (buffered in each connection's inbox)
  • Creates connections for new inbound peers (connect msg in inbox)
  • Checks monitors for disconnections
  • Removes and closes dead connections