bidirectional - calling rpc method each time when message arrived?

42 views
Skip to first unread message
Message has been deleted

tal bahalool

unread,
Apr 26, 2019, 1:43:41 AM4/26/19
to ej...@google.com, grp...@googlegroups.com
Hi Eric,
I have server that expose bidirectional method and i need to generate client that will send messages of max 5MB every 1-2 seconds.

Currently i'm creating client, and saving the instance as a member in my class and then for each message i'm calling rpc bidi method.

I wonder if i need to call the rpc bidi method once in start (process startup) and then save the full duplex instance as class member  and when message arrive just to call to the "write" method and when process go down call "end". 

1. what is the best practice in my case? performance issue
2. the connection to server start once when client created both cases? (just to be sure)

** i'm using javascript client
Thanks!

Eric Anderson

unread,
Apr 26, 2019, 11:34:03 AM4/26/19
to tal bahalool, grpc-io
Using individual RPCs for each message is fine. If, however, you are trying to get better performance on the server (not in transfer rates, but in processing rates), using a longer-lived bidi stream could be useful.

As I discussed in my KubeCon talk (slides are near "PDF" and video is "link to session recording"), longer-lived bidi streams are harder to use and open you to different problems. Long-lived RPCs in particular can require special care. So make sure you are solving a big enough problem by using such streams, so that you don't introduce complexity for little gain. That isn't to say "don't use long-lived, bidi streams." Long-lived, bidi streams are a life-saver in some cases. Just make sure it is worth it.

At the bare minimum, on the client you would need to manually handle the bidi stream getting closed/killed, would likely want to enable keepalive, and probably would also need acks back from the server. If you don't get an ack for a message before the stream goes down, you'd have to re-send it. On server-side, it is commonly good to close the connection occasionally to spread load. It's easiest to send a response to the client asking it to close the stream, so that you don't lose messages (when server closes, messages the client sends will be lost).

tal bahalool

unread,
Apr 27, 2019, 3:43:06 AM4/27/19
to Eric Anderson, grpc-io
Thanks! 
Reply all
Reply to author
Forward
0 new messages