proxystore.endpoint.endpoint¶
Endpoint implementation.
EndpointMode
¶
Endpoint
¶
Endpoint(
name: str | None = None,
uuid: UUID | None = None,
*,
peer_manager: PeerManager | None = None,
storage: Storage | None = None
)
ProxyStore Endpoint.
An endpoint is an object store with get
/set
functionality.
By default, an endpoint operates in
EndpointMode.SOLO
mode where the endpoint acts just as an isolated object store. Endpoints
can also be configured in
EndpointMode.PEERING
mode by initializing the endpoint with a
PeerManager
.
The PeerManager
is connected to a
relay server which is used to establish peer-to-peer connections with
other endpoints connected to the same relay server. After peer connections
are established, endpoints can forward operations between each
other. Peering is available even when endpoints are behind separate
NATs. See the proxystore.p2p
module to learn more
about peering.
Warning
Requests made to remote endpoints will only invoke the request on the remote and return the result. I.e., invoking GET on a remote will return the value but will not store it on the local endpoint.
Example
Solo Mode Usage
Example
Peering Mode Usage
pm1 = await PeerManager(RelayClient(...))
pm2 = await PeerManager(RelayClient(...))
ep1 = await Endpoint(peer_manager=pm1)
ep2 = await Endpoint(peer_manager=pm2)
serialized_data = b'data string'
await ep1.set('key', serialized_data)
assert await ep2.get('key', endpoint=ep1.uuid) == serialized_data
assert await ep1.exists('key')
assert not await ep1.exists('key', endpoint=ep2.uuid)
await ep1.close()
await ep2.close()
Note
Endpoints can be configured and started via the
proxystore-endpoint
command-line
interface.
Note
If the endpoint is being used in peering mode, the endpoint should be
used as a context manager or initialized with await. This will ensure
Endpoint.async_init()
is called which initializes the background task that listens for
incoming peer messages.
Parameters:
-
name
(str | None
, default:None
) –Readable name of the endpoint. Only used if
peer_manager
is not provided. Otherwise the name will be set toPeerManager.name
. -
uuid
(UUID | None
, default:None
) –UUID of the endpoint. Only used if
peer_manager
is not provided. Otherwise the UUID will be set toPeerManager.uuid
. -
peer_manager
(PeerManager | None
, default:None
) –Optional peer manager that is connected to a relay server which will be used for establishing peer connections to other endpoints connected to the same relay server.
-
storage
(Storage | None
, default:None
) –Storage interface to use. If
None
,DictStorage
is used.
Raises:
-
ValueError
–if neither
name
/uuid
orpeer_manager
are set.
Source code in proxystore/endpoint/endpoint.py
peer_manager
property
¶
peer_manager: PeerManager | None
Peer manager.
Raises:
-
PeeringNotAvailableError
–if the endpoint was initialized with a
PeerManager
butEndpoint.async_init()
has not been called. This is likely because the endpoint was not initialized with theawait
keyword.
async_init
async
¶
Initialize connections and tasks necessary for peering.
Note
This will also call
PeerManager.async_init()
if one is provided so that asynchronous resources for both the
PeerManager
and endpoint can be initialized later after creation.
Source code in proxystore/endpoint/endpoint.py
evict
async
¶
Evict key from endpoint.
Parameters:
-
key
(str
) –Key to evict.
-
endpoint
(UUID | None
, default:None
) –Endpoint to perform operation on. If unspecified or if the endpoint is on solo mode, the operation will be performed on the local endpoint.
Raises:
-
PeerRequestError
–If request to a peer endpoint fails.
Source code in proxystore/endpoint/endpoint.py
exists
async
¶
Check if key exists on endpoint.
Parameters:
-
key
(str
) –Key to check.
-
endpoint
(UUID | None
, default:None
) –Endpoint to perform operation on. If unspecified or if the endpoint is on solo mode, the operation will be performed on the local endpoint.
Returns:
-
bool
–If the key exists.
Raises:
-
PeerRequestError
–If request to a peer endpoint fails.
Source code in proxystore/endpoint/endpoint.py
get
async
¶
Get value associated with key on endpoint.
Parameters:
-
key
(str
) –Key to get value for.
-
endpoint
(UUID | None
, default:None
) –Endpoint to perform operation on. If unspecified or if the endpoint is on solo mode, the operation will be performed on the local endpoint.
Returns:
-
bytes | None
–Value associated with key.
Raises:
-
PeerRequestError
–If request to a peer endpoint fails.
Source code in proxystore/endpoint/endpoint.py
set
async
¶
Set key with data on endpoint.
Parameters:
-
key
(str
) –Key to associate with value.
-
data
(bytes
) –Value to associate with key.
-
endpoint
(UUID | None
, default:None
) –Endpoint to perform operation on. If unspecified or if the endpoint is on solo mode, the operation will be performed on the local endpoint.
Raises:
-
ObjectSizeExceededError
–If the max object size is configured and the data exceeds that size.
-
PeerRequestError
–If request to a peer endpoint fails.
Source code in proxystore/endpoint/endpoint.py
close
async
¶
Close the endpoint and any open connections safely.