Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling an out of memory exception gracefully in .NET (or avoiding it entirely)
    primarykey
    data
    text
    <p>I've got a job processor which needs to handle ~300 jobs in parallel (jobs can take up to 5 minutes to complete, but they are <em>usually</em> network-bound).</p> <p>The issue I've got is that jobs tend to come in clumps of a specific type. For simplicity, let's say there are six job types, <code>JobA</code> through <code>JobF</code>.</p> <p><code>JobA</code> - <code>JobE</code> are network bound and can quite happily have 300 running together without taxing the system at all (actually, I've managed to get more than 1,500 running side-by-side in tests). <code>JobF</code> (a new job type) is also network-bound, but it requires a considerable chunk of memory and actually uses GDI functionality.</p> <p>I'm making sure I carefully dispose of all GDI objects with <code>using</code>s and according to the profiler, I'm not leaking anything. It's simply that running 300 <code>JobF</code> in parallel uses more memory than .NET is willing to give me.</p> <p>What's the best practice way of dealing with this? My first thought was to determine how much memory overhead I had and throttle spawning new jobs as I approach the limit (at least <code>JobF</code> jobs). I haven't been able to achieve this as I can't find any way to reliably determine what the framework is willing to allocate me in terms of memory. I'd also have to guess at the maximum memory used by a job which seems a little flakey.</p> <p>My next plan was to simply throttle if I get OOMs and re-schedule the failed jobs. Unfortunately, the OOM can occur anywhere, not just inside the problematic jobs. In fact, the most common place is the main worker thread which manages the jobs. As things stand, this causes the process to do a graceful shutdown (if possible), restart and attempt to recover. While this works, it's nasty and wasteful of time and resources - far worse than just recycling that particular job.</p> <p>Is there a standard way to handle this situation (adding more memory is an option and will be done, but the application should handle this situation properly, not just bomb out)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload