pub struct RpcAgent { /* private fields */ }Expand description
RPC agent that manages function registration and remote invocation.
Each rank creates an RpcAgent wrapping a Backend. Functions are
registered with [register] and invoked remotely with [rpc_sync].
§Response correlation
Concurrent rpc_sync calls are correlated by request_id. If a received
response has a different request_id than expected, it is buffered and
the agent retries the recv. Buffered responses are checked before
issuing new recv calls.
Implementations§
Source§impl RpcAgent
impl RpcAgent
Sourcepub fn register<F>(&self, name: &str, handler: F)
pub fn register<F>(&self, name: &str, handler: F)
Register a callable function.
The handler receives serialized arguments and must return serialized results. If the registry lock is poisoned, this recovers the inner data and continues.
Sourcepub fn rpc_sync(
&self,
dst_rank: usize,
function_name: &str,
args: &[u8],
) -> FerrotorchResult<Vec<u8>>
pub fn rpc_sync( &self, dst_rank: usize, function_name: &str, args: &[u8], ) -> FerrotorchResult<Vec<u8>>
Invoke a function on a remote rank synchronously.
Sends the request, then waits for a response with the matching
request_id. If a response for a different request is received,
it is buffered for later retrieval.
§Errors
Returns an error if the remote function is not found, if the remote handler returns an error, or if communication fails.
Sourcepub fn rpc_async(
self: &Arc<Self>,
dst_rank: usize,
function_name: &str,
args: &[u8],
) -> JoinHandle<FerrotorchResult<Vec<u8>>>
pub fn rpc_async( self: &Arc<Self>, dst_rank: usize, function_name: &str, args: &[u8], ) -> JoinHandle<FerrotorchResult<Vec<u8>>>
Invoke a function on a remote rank asynchronously.
Spawns a thread to perform the RPC call. Returns a join handle that can be used to retrieve the result.
§Limitations
Spawns an unbounded number of OS threads. Each call to rpc_async
creates a new thread. This is acceptable for infrequent coordination
RPCs but is not suitable for high-frequency patterns. A thread pool
or async runtime would be needed for that use case.
Sourcepub fn handle_request(
&self,
src_rank: usize,
request_data: &[u8],
) -> FerrotorchResult<()>
pub fn handle_request( &self, src_rank: usize, request_data: &[u8], ) -> FerrotorchResult<()>
Handle an incoming RPC request: look up the function, call it, and send the response back.
Sourcepub fn world_size(&self) -> usize
pub fn world_size(&self) -> usize
The world size.
Auto Trait Implementations§
impl !Freeze for RpcAgent
impl !RefUnwindSafe for RpcAgent
impl Send for RpcAgent
impl Sync for RpcAgent
impl Unpin for RpcAgent
impl UnsafeUnpin for RpcAgent
impl !UnwindSafe for RpcAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more