0

I have a process that takes a very large amount of memory, it involves manipulating large images. The process is called via get request route, and I currently have a lock on the image creation method. Without the lock, if I send more than 10+ requests at once, the application memory immediately spikes and throws an exception.

[HttpGet]
[Route("example")]
public HttpResponseMessage GetImage([FromUri]ImageParams imageParams){

   lock (myLock){
   return CreateImage(imageParams);
   }

}

Someone mentioned increasing the applicationPool in another question, but I can't figure out how to do it. I think this would be a better alternative to locking, because I could still use a couple of threads to create images, but could limit this so I don't run out of memory. I am under the impression that .NET is using an integrated thread pooling system for each GET request. I am sure from testing that these requests are somehow run in parallel, and it would be helpful to decrease the potential number of threads rather than locking it to one.

Looking at this resource, https://msdn.microsoft.com/en-us/library/dd560842(v=vs.110).aspx

I've tried adding this element to the System.Web section but it says it is not a valid child element (even though I am running IIS version 10)

I was able to change the aspnet.config file to change the applicationPool number from 0 (default, no limit) to 1 and 3 but this did not yield any different results at all.

Any input would be appreciated, thanks for reading

Edit:

This is a followup from my question at this link, which shows the code where these errors are pointing me and some efforts to analyze..

Diagnosing OutOfMemory issues with Image Processing API in ASP.NET

Community
  • 1
  • 1
Jaked222
  • 326
  • 3
  • 15
  • What exception is thrown? `OutOfMemoryException`? What is the target framework, and what kind of `Application Pool` is it running in (pipeline, x86/x64 etc)? Do you have a memory limit on the application pool? – user1429080 Jan 12 '17 at 15:16
  • OutOfMemoryException and occasionally ArgumentException on my image resizing method. I suppose this is happening because the resize isn't locked.. but the memory is still spiking above the available line in diagnostics so this is probably the main problem. Target framework .NET 4.5.2. Not sure where to look for the application pool type... – Jaked222 Jan 12 '17 at 15:22
  • You may need to involve some library for dealing with the images. See for instance [this question](http://stackoverflow.com/q/1528525/1429080). Classes in `System.Drawing` doesn't seem to be officially supported in Asp.Net application, which probably means Microsoft has decided that there are too many pitfalls with them... – user1429080 Jan 12 '17 at 15:32
  • This is interesting and I'll have to keep it in mind.. Although this would require a pretty large overhaul and I still imagine that reducing the number of threads my application can run will solve my problem with one line of code.. – Jaked222 Jan 12 '17 at 15:46
  • How do you free your resources? Images are unmanaged resources and have to be disposed properly, do you do that after writing the response? – VMAtm Jan 17 '17 at 10:51
  • all of the images are being assigned within using statements during processing so I think they are being disposed properly.. – Jaked222 Jan 17 '17 at 14:49

0 Answers0