grpc / grpc/grpc-node

High concurrent environment will lead to slow response?

Open
#1,889 2 comments 0 reactions 0 assignees View on GitHub
package: @grpc/grpc-js
Dominant language
TypeScript
Stars
4.8k
Forks
716
Avg merge
2d 3h
Merged PRs (30d)
10

Description

### Problem description
I add a interceptor for grpc client to log :
```
const interceptor = function(options, nextCall) {
const requester = {
start: function(metadata, listener, next) {
var newListener = {
onReceiveMetadata: function(metadata, next) {
next(metadata);
},
onReceiveMessage: function(message, next) {
const responseTime = (new Date()).getTime() - (options.bxhStartTime as Date).getTime();
// exceeds 50ms to log
if (responseTime >= 50) {
const dayBeginUnixTime = Math.floor(new Date().setHours(0, 0, 0, 0) / 1000);
redis.lpush(slowKey, JSON.stringify({
responseTime: responseTime,
path: options.method_definition.path,
time: new Date(),
}));
}
next(message);
},
onReceiveStatus: function(status, next) {
next(status);
}
};
next(metadata, newListener);
},
sendMessage: function(message, next) {
options.bxhStartTime = new Date();
next(message);
},
};
return new grpc.InterceptingCall(nextCall(options), requester);
};
```
Sometimes response time can reach 1012ms:
```
{
"responseTime": 1012,
"path": "********",
"time": "2021-08-31T07:20:05.653Z"
}
```
This problem will result in slow http response and I want to know hot to fix it temporarily😭.

### Reproduction steps
**Only will happen in high concurrent environment.**

### Environment
- OS name [Ubuntu 20.04 amd64]
- Node version [v14.17.1]
- Package name and version ["@grpc/grpc-js": "^1.3.7"]

### Additional context
I will invoke many rpc service in one method:
```
const allResult = await Promise.all([
rpcService.getA(),
rpcService.getB(),
rpcService.getC(),
rpcService.getD(),
rpcService.getE(),
rpcService.getF(),
rpcService.getG(),
rpcService.getH(),
rpcService.getI(),
rpcService.getJ(),
]);
```
Does it matter?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.