You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to detect a slowly receiving client in a long-lived streaming RPC in asio-grpc (or grpc itself)? I am working on a server application that sends data to clients using streaming RPCS, and I would like to detect slowly receiving clients and then drop the connection with them since it can lead to queuing up data on sockets, potentially resulting in slowing down the server or ooming it. Could such a mechanism be implemented with asio-grpc?
Thanks in advance.
The text was updated successfully, but these errors were encountered:
Asio-grpc just acts as a small wrapper around gRPC's API. In the case of a client-streaming RPC, for example, that would be grpc::ServerAsyncWriter::Write. If that call really completes slowly for slow clients (I haven't tested it, also note this set_write_through option), then you can use it to automatically drop the connection like so:
constauto slow_threshold = std::chrono::seconds(5);
agrpc::Alarm alarm{grpc_context};
auto [completion_order, alarm_ok, write_ok] =
co_awaitasio::experimental::make_parallel_group(
alarm.wait(std::chrono::system_clock::now() + slow_threshold, asio::deferred),
rpc.write(response, asio::deferred))
.async_wait(asio::experimental::wait_for_one{}, asio::use_awaitable);
if (!write_ok)
{
// client dropped connection or was slow (alarm finished and caused cancellation of rpc with invokes grpc::ServerContext::TryCancel)co_return;
}
Hi Tradias,
Is there a way to detect a slowly receiving client in a long-lived streaming RPC in asio-grpc (or grpc itself)? I am working on a server application that sends data to clients using streaming RPCS, and I would like to detect slowly receiving clients and then drop the connection with them since it can lead to queuing up data on sockets, potentially resulting in slowing down the server or ooming it. Could such a mechanism be implemented with asio-grpc?
Thanks in advance.
The text was updated successfully, but these errors were encountered: