I have .NET Core 3.1 Web API in a docker container on Linux.
I use test tool that makes 1000 sequential requests to the Web API.
The Web API controller looks like this:
public MyController(ISendService sservice)
{
_sservice = sservice;
}
[HttpPost()]
public async Task<IActionResult> SendMessage([FromBody] SendMessageRequest request)
{
await _sservice.SendIt(request.Message);
}
My Send Service looks like this:
public class SendService: ISendService
{
private readonly HttpClient _client;
public SendService(HttpClient client)
{
_client = client;
}
public async Task SendMessage(string data)
{
var request= new HttpRequestMessage(HttpMethod.Post, "https://somelocation/test") { Version = new Version(2, 0) };
request.Content = new StringContent(data);
var response = await _client.SendAsync(request);
//Log response
}
}
I add the SendService in Startup like so:
services.AddHttpClient<ISendService, SendService>().ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler { SslProtocols = SslProtocols.Tls12 };
var store = new Store.GetStore();
handler.ClientCertificates.Add(store.certificate);
return handler;
});
My problem is that whenever SendMessage is called, the memory usage inside docker container goes up with each request. i.e. I call it 10 times, the memory will go up and stay there. I call it 1000 times, the memory goes up and up, beyond 85% (read that the limit should be 75% in .NET Core 3.1) and stay there even waiting 20 minutes with each test scenario.
Why does it not appear to garbage collect or release the memory? I running tests but I think it will reach 100% and the service will stop which is not good. Thank you