简体   繁体   中英

gRPC KeepAlive/idletimeout

I am trying to understand how keepalive or idle connection works with gRPC. I have bidirectional streaming RPC, where I create session and do nothing so that there is no activity on the channel.

  1. If there is no activity, GRPC_ARG_KEEPALIVE_TIME_MS signal will be blocked ( https://github.com/grpc/grpc/blob/master/doc/keepalive.md#faq ) and connection will be closed after this interval, however, it does not terminate and I see keepalive ping is sent and received. why?

  2. If we do not set any params, is there any timeout after which connection will be automatically closed? If yes, how do I change this behaviour, which param?

What is happening here is that maybe GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS parameter is true that's why it is sending the pings even without connection.

GRPC_ARG_KEEPALIVE_TIMEOUT_MS is controlling the timeout as written in the documentation:

This channel argument controls the amount of time (in milliseconds) the sender of the keepalive ping waits for an acknowledgement. If it does not receive an acknowledgment within this time, it will close the connection.

You can manually adjust this parameter to control the timeout duration.

Set the GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS to false so it cannot send keepAlive pings when there is no active call.

A KeepAlive parameter is what's used to ensure the connection stays open and to indicate to the server and client that it's still connected and responding.

You can see a low-level view of this in action here .

On the other hand, the Idle Connections parameter closes connections after no requests have been sent over the connection (not the keep-alive packets, this refers to the application level packets). This is good since idle connections occupy memory, CPU, and an open socket, all finite resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM