Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc-js version 1.12.2, there is a phenomenon of memory growth after use #2870

Open
moumou9215 opened this issue Dec 12, 2024 · 3 comments
Open

Comments

@moumou9215
Copy link

Problem description

Update to [email protected] Version, experiencing continuous memory growth issue

Reproduction steps

nodejs:
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const packageDefinition = protoLoader.loadSync(
proto文件路径,
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
},
);
const dataService = grpc.loadPackageDefinition(packageDefinition);

// The testProto() access is called in real-time and requests every 3 seconds
export const testProto= () => {
const grpcOptions = {};
const client = new dataService.DataMessage(URL, grpc.credentials.createInsecure());
return new Promise((resolve, reject) => {
client.getInfo(grpcOptions, (err, output) => {
if (err) {
reject(err);
} else {
resolve(output);
}
});
});
};

@murgatroid99
Copy link
Member

In your testProto function, you create a new client object, but you never close that client. Because of that, it continues to retain memory after you stop using it. We recommend creating a single client and using it for every request, but if that is not an option, you should at least call client.close() when you are done with it.

@moumou9215
Copy link
Author

Create a client in Node.js and use it for each request (with real-time refresh), and whether there is a need to close or perform other operations afterwards.
Which of the following two methods is better in terms of performance

  1. Create a client for each request
  2. Call client. close() after each request is completed

@murgatroid99
Copy link
Member

Your best option is to create a single client object, and use that single client to make every request. This performs better because it ensures that resources such as connections are reused as much as possible.

Your other option is to create a client for each request and call client.close() after the request completes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants