The controller for my API .NET 4.5.2 is running out of memory when many simultaneous get requests are happening. The out of memory comes from a memory stream downloading large images, which is part of the processing that the request needs to do.
Is there any way besides locking the process method that I can reduce the amount of threads that run at the same time? IE only allow 2-3 process methods to be running at the same time.. This would allow for maximum efficiency while also not running out of memory. Locking the process does fix the out of memory but only allows one process at a time which is not using all the available memory and reduces runtime.
I'm not sure how to access or keep track of the threads that are being created whenever a GET request comes into my api. It is deployed to an Azure server, maybe there is a tool for this? Right now the way I'm accommodating for many users at once is by scaling to multiple instances.
[HttpGet]
[Route("example")]
public HttpResponseMessage GetImage([FromUri] ImageParams imageParams){
Image template = Image.FromFile(
System.Web.Hosting.HostingEnvironment.MapPath("~/Content/Images/image.png");
return ProccessImage(imageParams, template);
}
Out of memory is thrown on the Image.FromFile line, because the API tries to download all the files at once.