Server-side memory leaks
See original GitHub issueWhat version of gRPC and what language are you using?
-
dotnet version 6
-
Grpc packages:
Google.Protobuf ==> Version=“3.23.1”
Grpc.AspNetCore.Server.ClientFactory ==> Version=“2.55.0”
Grpc.Net.Client ==> Version=“2.55.0”
Grpc.Tools ==> Version=“2.55.1”
What operating system (Linux, Windows,…) and version?
Windows 10 [version 10.0.19045.3208]
Scenario
Following the example from the official website, a simple demo was written. I found that grpc-service memory kept going up and not down, even when I closed the calling client, the memory still did not go down
server code
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(4999, listenOptions => listenOptions.Protocols = HttpProtocols.Http2);
});
builder.Services.AddGrpc();
var app = builder.Build();
app.MapGrpcService<GreeterService>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. ");
app.Run();
}
public class GreeterService : Greeter.GreeterBase
{
public GreeterService()
{
}
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
{
Console.WriteLine($"Starting call. Request: {request}");
return Task.FromResult(new HelloReply
{
Message = "Hello " + request.Name
});
}
}
client code
static void Main(string[] args)
{
using var channel = GrpcChannel.ForAddress("http://127.0.0.1:4999");
var client = new Greeter.GreeterClient(channel);
//Press Enter and call grpc service 100 times
while (string.IsNullOrWhiteSpace(Console.ReadLine()))
{
for(int i = 0; i < 100; i++)
{
var reponse = client.SayHello(new HelloRequest() { Name =$"zeke-{i}" });
}
}
Console.WriteLine("bye!");
Console.ReadLine();
}
protos
syntax = "proto3";
option csharp_namespace = "GrpcService1";
package greet;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply);
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings.
message HelloReply {
string message = 1;
}
-
After the service is started, the memory is monitored as follows
name memory GrpcService1.exe 44,568 k -
The client calls 500 times for the first time, the memory check is as follows
name memory GrpcService1.exe 49,188 k -
The client calls 500 times for the second time, the memory is checked as follows
name memory GrpcService1.exe 49,316 k -
After repeating the previous step N times, close the client and check for memory as follows
name memory GrpcService1.exe 55,840 k
As you can see, the memory keeps growing and is not reclaimed
I want to be consulted. Is there a problem with my usage? or Is there a memory leak in grpc?.
Look forward to your reply,Thanks for helping!
Issue Analytics
- State:
- Created 2 months ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Thank you so much @gfoidl
This is the normal behavior of the .NET GC.
In the client do something like
then – when the GC determines to run – the memory usage can drop…see link above.
Under a profiler (the one from VS) it looks on my machine like
The red vertical bars show when the GC kicks in to collect objects. Can also be seen in the “Live Objects” graph above.