I must be doing something wrong... my gRPC server is implemented in node.js:
function handler(call, callback) {
console.log('Received request at ' + Date.now());
setTimeout(() => {
callback({ message: 'Done and done' });
}, 100);
}
If I call it 1,000 in Node, I get 1,000 responses in about 100ms:
const resps = [];
for (let i = 0; i < 1000; i += 1) {
client.doit({ data }, (err, resp) => {
resps.push(resp);
if (resps.length === 1000) {
onDone();
}
});
}
However, calling the server from Python using the service.future I can see the server only receiving a request after the previous one has returned:
for _ in range(1000):
message = Message(data=data)
resp = client.doit.future(message)
resp = resp.result()
resps.append(resp)
I get that Node's IO paradigm is different (everything is async; event loop; etc.), and the Python example above blocks on out.result()
, but my question is: can could I change/optimize the Python client so it can make multiple calls to my server without waiting for the first one to return?