Why ASP.NET holds on to unmanaged memory? -
i have asp.net 4.0 application has been growing on years in terms of number of pages , number of daily users. @ 1 point started failing "http error 503. service unavailable." 1 time every day @ 12pm (peak load time). restarting app pool fixed day or two.
examining scheme logs showed app pool recycled every min , 1 time in bluish moon rapid fail protection kicked in , stopped app pool. here typical scenario (abbreviated clarity):
2014-06-10 07:30:53 5117 4 info event worker process process id of '4060' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:31:53 5117 4 info event worker process process id of '16764' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:33:53 5117 4 info event worker process process id of '18632' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:34:53 5117 4 info event worker process process id of '49096' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:35:53 5117 4 info event worker process process id of '8960' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:36:53 5117 4 info event worker process process id of '31384' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:37:53 5117 4 info event worker process process id of '37244' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:38:53 5117 4 info event worker process process id of '12864' serving application pool 'slepov-27' has requested recycle because reached private bytes memory limit. 2014-06-10 07:39:11 5002 1 error event application pool 'slepov-27' beingness automatically disabled due series of failures in process(es) serving application pool. disabling rapid fail protection not alternative app runs on shared hosting.
my guess recycles trigger rapid fail protection , recycles caused exceeding memory limits on app pool. memory limit set @ 400m (not sure which, working set or commit size - emailed support).
i have set on find out typical memory usage of app in 1 user scenario. have run in iis (7) on dev machine , looked @ working set , commit size in task manager. 1 thing surprised me this: memory went 3-6 megs every page opened while pages did not contain much code, mark-up. given web site 100 pages, going on 400m did not seem unlikely.
another surprise pages did processing (mostly in-memory calculations, no database or web service calls). , problem such pages ramped memory 200m , memory not reclaimed. sure there nil holding on memory , confirmed ants. 'bytes in heaps' goes after page finishes processing 'private bytes' not.
to isolate problem farther have set test app (source code), 2 apps in fact, 1 console , 1 asp.net. allow allocate 1gb of memory , phone call gc.collect. simple. results strikingly different between console , asp.net:
working private commit run console app 6 1 5 allocate 1gb. press come in go on ... 1082 1076 1082 allocated 1gb. press come in deallocate ... 1082 1076 1082 press come in gc.collect ... 16 10 16 press come in exit ... run asp.net app 36 15 102 new 1gb 1131 1110 1326 gc.collect 570 548 764 wait 10 mins 570 548 764 new 1gb 1132 1111 1322 gc.collect 575 554 764 gc.collect 575 554 764 as can see console app (almost) goes original memory usage after gc.collect called while asp.net app keeps holding on more half gig of memory.
as seen in ants screenshot, managed memory (bytes in heaps) freed, unmanaged (private bytes) not exclusively freed. why?
i have set <compilation debug="false" /> advised many sources.
i have looked @ these similar questions (and many more):
unmanaged memory in .net 4 application pool
worker process recycles because reached virtual memory limit
to sum up, main question why unmanaged memory not freed exclusively after gc.collect? great if explain gradual stepping in memory usage every new open page. thanks.
asp.net memory-management
No comments:
Post a Comment