Implement client-server session.

80 views
Skip to first unread message

Komal Desai

unread,
Nov 1, 2022, 11:02:29 AM11/1/22
to grpc.io
Hi,

My grpc server wants to implement simple cluster management where all nodes connect to my grpc server.

If the node goes down, i want my server to let other nodes know that a particular node has gone down.

I have written bi-directional streaming api for periodic update. 
I wanted to know is there a way to implement "session" concept for cluster-mgmt usecase.

thanks,
komal

sanjay...@google.com

unread,
Nov 1, 2022, 12:31:30 PM11/1/22
to grpc.io
Which gRPC language are you using? Also I am not sure I understand the session concept for the cluster mgmt use-case.

There is a gRFC pull request at https://github.com/grpc/proposal/pull/319 that proposes a cookie based session affinity but not sure if that addresses your question.

Komal Desai

unread,
Nov 1, 2022, 12:47:45 PM11/1/22
to grpc.io
In Cluster-Management,  each node has to heartbeat with a server on regular basis to indicate that it is alive.
When the node-A is down,  server will detect that and inform other nodes that  node-A is down.

In gRPC,  clients use Channel to connect to the server and gRPC keeps the connection alive. But how does Server get the list of clients (nodes) and which clients are alive etc. 

I am currently using JAVA but open to any other language binding if there is a way to implement above very easily.

thanks,
Komal 

sanjay...@google.com

unread,
Nov 1, 2022, 2:32:00 PM11/1/22
to grpc.io

Komal Desai

unread,
Nov 1, 2022, 5:53:41 PM11/1/22
to sanjay...@google.com, grpc.io
Thanks @Sanjay for quick response.
This is more like a debugging tool. If I want to implement something
like this in my grpcServer interface, is it possible to get this info
as part of Channel object itself?

thanks,
komal
> --
> You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/ODXWewW32cg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/3ce9c3d2-8cf8-422b-858a-b476d4318504n%40googlegroups.com.

sanjay...@google.com

unread,
Nov 1, 2022, 8:00:21 PM11/1/22
to grpc.io
Note that channelz is not necessarily a debugging tool - it can be used for monitoring use-cases as well. But I do admit that it gives you only a snapshot so you have to keep polling to detect addition/deletion.

I have a better idea: you can use a streaming RPC for both heart-beats and node-down event notification to other nodes. You will have to add some business logic in your streaming RPC server side as follows:

- it maintains a list/table of currently active connected clients
- on each new serverCall it uses Grpc.TRANSPORT_ATTR_REMOTE_ADDR to get the remote IP (example here) and add it to the list if not already there
- if the call gets dropped/disconnected/completed for any reason (receiving onHalfClose(), onCancel() or onComplete()) then it implies the node is not alive any more and use the same Grpc.TRANSPORT_ATTR_REMOTE_ADDR  trick to get the remote IP to remove that IP from your list and at the same time add an event to an event queue that will be used to inform other nodes of this event (so you do this asynchronously instead of blocking the original thread where you received the serverCall listener event.

Hope that helps.

Komal Desai

unread,
Nov 1, 2022, 8:21:07 PM11/1/22
to sanjay...@google.com, grpc.io
This is super helpful. I will give it a try.
Thanks,
komal

On Tue, Nov 1, 2022 at 5:00 PM 'sanjay...@google.com' via grpc.io
> To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/952271fe-33b8-4793-b883-96d3eb37615dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages