gRPC - node.js simultaneous client calls - reverse ordered

23 views
Skip to first unread message

vijeth AG

unread,
Aug 10, 2020, 11:51:13 AM8/10/20
to grpc.io
Hi,

I have started exploring gRPC with Node.js, by basic hello world level client-server js.

Code gist snippets and outputs below.

I have noticed a strange thing If I instantiate a client and call remote function 3/4 times simultaneously, the responses of the calls are printed in reverse order - Last called rpc prints out first.

Hello.proto

server.js

client.js

Actual output: on running client.js

3  Sayhello: Hello 3
2  Sayhello: Hello 2
1  Sayhello: Hello 1

I was expecting in the order 1,2,3

Also debugged server.js - the first value received in sayHelloFunction is 3.

I if I add delay in between call works in the order 1,2,3 as expected.

Please Im curious what am I missing. 

Thanks in advance

Michael Lumish

unread,
Aug 10, 2020, 12:17:49 PM8/10/20
to vijeth AG, grpc.io
Those requests all happen independently. We don't make any guarantees about their order, so the library internals are free to reorder them before sending them out. In this case, the first requests you make after you construct the client object cause it to start connecting, so those requests will be queued before sending them out, making them more likely to be reordered.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, 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/d3353aef-9770-45bb-ae75-058e5905f414n%40googlegroups.com.

vijeth AG

unread,
Aug 10, 2020, 1:04:11 PM8/10/20
to Michael Lumish, grpc.io
So on the 1st call, while connection is in progress, any subsequent client calls made are stacked up. once the connection is established the call stack is resolved.

Just to validate: I made 3 calls after a 1st init call gets resolved as in code below.  Prints in the order of 1,2,3 

Thanks for your reply.

client.sayHello({name: "init"}, function(err, response) {
console.log('init complete', response.message);

client.sayHello({name: "1"}, function(err, response) {
console.log('1 Sayhello:', response.message);
});
client.sayHello({name: "2"}, function(err, response) {
console.log('2 Sayhello:', response.message);
});
client.sayHello({name: "3"}, function(err, response) {
console.log('3 Sayhello:', response.message);
});
});
--
Regards
vijeth

Michael Lumish

unread,
Aug 10, 2020, 1:38:20 PM8/10/20
to vijeth AG, grpc.io
I just want to make sure it's clear that the ordering behavior you have observed here is not guaranteed. Requests made before a connection is established are not necessarily reversed, the connection state internally may change after a connection is established, and requests on the same client may even get sent to different servers, making their order completely independent.

vijeth AG

unread,
Aug 10, 2020, 3:11:59 PM8/10/20
to Michael Lumish, grpc.io
Gotit. Thanks
--
Regards
vijeth
Reply all
Reply to author
Forward
0 new messages