proxystore.endpoint.client¶
Client for communicating with a local endpoint.
Note
Clients communicate with endpoints on the local network over TCP using
the protocol defined in
proxystore.endpoint.protocol.
It is not intended that clients from outside the local network interact
with an endpoint this way. (Rather, they should connect to their own
local endpoint, which peers with remote endpoints.)
REQUEST_TIMEOUT
module-attribute
¶
Default seconds a request to the local endpoint can go without progress.
EndpointClient
¶
EndpointClient(
sock: socket,
info: EndpointInfo,
*,
protocol_version: int,
request_timeout: float | None = REQUEST_TIMEOUT,
)
Connection to a local endpoint.
Use from_name()
to connect to a local endpoint by name, or
connect() to
connect to an address directly.
Warning
A client is not thread-safe because a connection can only process one request at a time. Use a separate client per thread.
Example
Parameters:
-
sock(socket) –Connected socket that has completed the handshake.
-
info(EndpointInfo) –Information about the endpoint.
-
protocol_version(int) –Protocol version negotiated in the handshake.
-
request_timeout(float | None, default:REQUEST_TIMEOUT) –Seconds a request handled by this endpoint can go without sending or receiving any data, including while the endpoint handles the request (e.g., writes the object to its storage), before it fails with an
EndpointTimeoutError. Requests forwarded to a peer endpoint have no timeout in the client because the endpoint does not respond until the peer does. IfNone, requests have no timeout.
Raises:
-
ValueError–If
request_timeoutis not positive.
Source code in proxystore/endpoint/client.py
connect
classmethod
¶
connect(
host: str,
port: int,
token: EndpointToken,
*,
tls_fingerprint: str | None = None,
timeout: float | None = 10,
request_timeout: float | None = REQUEST_TIMEOUT,
) -> Self
Connect to an endpoint and complete the handshake.
Parameters:
-
host(str) –Host address of the endpoint.
-
port(int) –Port of the endpoint.
-
token(EndpointToken) –Token of the endpoint (see
EndpointDir.read_connection()). -
tls_fingerprint(str | None, default:None) –SHA-256 fingerprint of the endpoint's TLS certificate (see
EndpointDir.read_connection()). If provided, the connection is encrypted with TLS and the endpoint's certificate must match the fingerprint. -
timeout(float | None, default:10) –Timeout in seconds for connecting and completing the handshake.
-
request_timeout(float | None, default:REQUEST_TIMEOUT) –Seconds a request can go without progress (see
EndpointClient).
Warns:
-
VersionMismatchWarning–If the endpoint uses a different ProxyStore version or Python minor version than this client.
Raises:
-
ValueError–If
request_timeoutis not positive. -
EndpointNotRunningError–If the connection is refused.
-
EndpointConnectionError–If the connection cannot be established or is lost during the handshake (e.g., a timeout).
-
EndpointAuthError–If the client or endpoint fails authentication.
-
EndpointProtocolError–If the endpoint uses an incompatible protocol.
Source code in proxystore/endpoint/client.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
from_dir
classmethod
¶
from_dir(
endpoint_dir: EndpointDir,
*,
timeout: float | None = 10,
request_timeout: float | None = REQUEST_TIMEOUT,
) -> Self
Connect to a local endpoint using its connection file.
The connection file is read each time because the endpoint writes a new one each time it starts.
Parameters:
-
endpoint_dir(EndpointDir) –Directory of the endpoint.
-
timeout(float | None, default:10) –Timeout in seconds for connecting and completing the handshake.
-
request_timeout(float | None, default:REQUEST_TIMEOUT) –Seconds a request can go without progress (see
EndpointClient).
Raises:
-
EndpointNotFoundError–If the endpoint directory does not exist.
-
EndpointNotRunningError–If the endpoint's connection file does not exist (i.e., the endpoint is not running).
-
EndpointAuthError–If the connection file cannot be read or is malformed.
-
EndpointError–If the connection or handshake fails (see
connect()).
Source code in proxystore/endpoint/client.py
from_name
classmethod
¶
from_name(
name: str,
*,
proxystore_dir: str | None = None,
timeout: float | None = 10,
request_timeout: float | None = REQUEST_TIMEOUT,
) -> Self
Connect to a local endpoint by name.
Parameters:
-
name(str) –Name of the endpoint.
-
proxystore_dir(str | None, default:None) –ProxyStore home directory containing the endpoint. Defaults to
home_dir(). -
timeout(float | None, default:10) –Timeout in seconds for connecting and completing the handshake.
-
request_timeout(float | None, default:REQUEST_TIMEOUT) –Seconds a request can go without progress (see
EndpointClient).
Raises:
-
EndpointNotFoundError–If no endpoint with the name exists.
-
EndpointError–If connecting to the endpoint fails (see
from_dir()).
Source code in proxystore/endpoint/client.py
close
¶
Close the connection.
evict
¶
Evict the object associated with the key.
Parameters:
-
key(str) –Key associated with object to evict.
-
target(str | None, default:None) –Optional ID of a peer endpoint to forward the operation to.
Raises:
-
ValueError–If
targetis not a valid endpoint ID. -
EndpointError–If the request fails.
Source code in proxystore/endpoint/client.py
exists
¶
Check if an object associated with the key exists.
Parameters:
-
key(str) –Key potentially associated with stored object.
-
target(str | None, default:None) –Optional ID of a peer endpoint to forward the operation to.
Returns:
-
bool–If an object associated with the key exists.
Raises:
-
ValueError–If
targetis not a valid endpoint ID. -
EndpointError–If the request fails.
Source code in proxystore/endpoint/client.py
get
¶
Get the serialized object associated with the key.
Parameters:
-
key(str) –Key associated with object to retrieve.
-
target(str | None, default:None) –Optional ID of a peer endpoint to forward the operation to.
Returns:
-
bytearray | None–Serialized object or
Noneif the object does not exist.
Raises:
-
ValueError–If
targetis not a valid endpoint ID. -
EndpointError–If the request fails.
Source code in proxystore/endpoint/client.py
set
¶
Set the serialized object associated with the key.
Parameters:
-
key(str) –Key to associate with the object.
-
data(BytesLike) –Serialized object.
-
target(str | None, default:None) –Optional ID of a peer endpoint to forward the operation to.
Raises:
-
ObjectSizeExceededError–If the size of
dataexceeds the maximum object size of the endpoint. -
ValueError–If
targetis not a valid endpoint ID. -
EndpointError–If the request fails.
Source code in proxystore/endpoint/client.py
ping
¶
ping(target: str | None = None) -> PingResult
Measure the latency of and path to a peer endpoint.
The local endpoint sends a request to the peer and reports the time until it received the response and the network path of the connection. The first ping to a peer includes the time to establish the connection.
Parameters:
-
target(str | None, default:None) –Optional ID of the peer endpoint to ping. If
None, the local endpoint is pinged.
Raises:
-
ValueError–If
targetis not a valid endpoint ID. -
EndpointError–If the request fails.
Source code in proxystore/endpoint/client.py
check_request_timeout
¶
Check that a request timeout is positive or None.
Raises:
-
ValueError–If
timeoutis not positive.