@Operator public final class TryRpc extends PrimitiveOp
This op asynchronously performs either a single RPC request, or a batch of requests. RPC requests are defined by three main parameters:
- `address` (the host+port or BNS address of the request) - `method` (the method name for the request) - `request` (the serialized proto string, or vector of strings, of the RPC request argument).
For example, if you have an RPC service running on port localhost:2345, and its interface is configured with the following proto declaration:
service MyService {
rpc MyMethod(MyRequestProto) returns (MyResponseProto) {
}
};
then call this op with arguments:
address = "localhost:2345"
method = "MyService/MyMethod"
The `request` tensor is a string tensor representing serialized `MyRequestProto`
strings; and the output string tensor `response` will have the same shape
and contain (upon successful completion) corresponding serialized
`MyResponseProto` strings.
For example, to send a single, empty, `MyRequestProto`, call this op with `request = ""`. To send 5 parallel empty requests, call this op with `request = ["", "", "", "", ""]`.
More generally, one can create a batch of `MyRequestProto` serialized protos from regular batched tensors using the `encode_proto` op, and convert the response `MyResponseProto` serialized protos to batched tensors using the `decode_proto` op.
NOTE Working with serialized proto strings is faster than instantiating actual proto objects in memory, so no performance degradation is expected compared to writing custom kernels for this workflow.
Unlike the standard `Rpc` op, if the connection fails or the remote worker returns an error status, this op does not reraise the exception. Instead, the `status_code` and `status_message` entry for the corresponding RPC call is set with the error returned from the RPC call. The `response` tensor will contain valid response values for those minibatch entries whose RPCs did not fail; the rest of the entries will have empty strings.
Modifier and Type | Class and Description |
---|---|
static class |
TryRpc.Options
Optional attributes for
TryRpc |
operation
Modifier and Type | Method and Description |
---|---|
static TryRpc |
create(Scope scope,
Operand<String> address,
Operand<String> method,
Operand<String> request,
TryRpc.Options... options)
Factory method to create a class wrapping a new TryRpc operation.
|
static TryRpc.Options |
failFast(Boolean failFast) |
static TryRpc.Options |
protocol(String protocol) |
Output<String> |
response()
Same shape as `request`.
|
Output<Integer> |
statusCode()
Same shape as `request`.
|
Output<String> |
statusMessage()
Same shape as `request`.
|
static TryRpc.Options |
timeoutInMs(Long timeoutInMs) |
equals, hashCode, op, toString
public static TryRpc create(Scope scope, Operand<String> address, Operand<String> method, Operand<String> request, TryRpc.Options... options)
scope
- current scopeaddress
- `0-D` or `1-D`. The address (i.e. host_name:port) of the RPC server.
If this tensor has more than 1 element, then multiple parallel rpc requests
are sent. This argument broadcasts with `method` and `request`.method
- `0-D` or `1-D`. The method address on the RPC server.
If this tensor has more than 1 element, then multiple parallel rpc requests
are sent. This argument broadcasts with `address` and `request`.request
- `0-D` or `1-D`. Serialized proto strings: the rpc request argument.
If this tensor has more than 1 element, then multiple parallel rpc requests
are sent. This argument broadcasts with `address` and `method`.options
- carries optional attributes valuespublic static TryRpc.Options protocol(String protocol)
protocol
- RPC protocol to use. Empty string means use the default protocol.
Options include 'grpc'.public static TryRpc.Options failFast(Boolean failFast)
failFast
- `boolean`. If `true` (default), then failures to connect
(i.e., the server does not immediately respond) cause an RPC failure.public static TryRpc.Options timeoutInMs(Long timeoutInMs)
timeoutInMs
- `int`. If `0` (default), then the kernel will run the RPC
request and only time out if the RPC deadline passes or the session times out.
If this value is greater than `0`, then the op will raise an exception if
the RPC takes longer than `timeout_in_ms`.public Output<String> response()
public Output<Integer> statusCode()
Copyright © 2022. All rights reserved.