How to get Kentico's memory via C?

Duane Bryant asked on March 12, 2020 07:23

I as of late ran over an out of memory special case when clients would visit scarcely any pages of my Kentico site. Quick forward - I found that the dispensed memory (System > General) was more than 2 GB! I at that point went to Debug > Clear reserve and afterward saw the dispensed memory sitting generally around 400 MB (phew..). Presently, when the clients would visit the page, it would work with no out of memory exemption.

Is there a way I could get these memory statistics via code (ideally C#)? I'm thinking of being able to regularly monitor these memory statistics and trigger an alert (send an email/post to webhook from my C# code) when the allocated memory gets too high ?

Correct Answer

Brenden Kehren answered on March 12, 2020 14:12

If you look at Kentico's requirements for servers/hosting, 4GB is the minimum amount of memory is requires and recommends 8GB. So having a site which has 2GB of memory in use is pretty good.

If you check out the /CMSModules/System/Controls/System.ascx.cs file, you'll find the following methods about line 613:

SystemHelper.GetVirtualMemorySize()
SystemHelper.GetWorkingSetSize()
SystemHelper.GetPeakWorkingSetSize()

2 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on March 12, 2020 10:30

Hi Duane,

What exact memory statistics are you talking about? Allocated, peak, physical, virtual? 2 GB is not much at all! Some of our large websites consume 35+ GB of RAM. And be mindful that it contains all your Kentico caches. If you just clear it - all your filled caches are gone! So first of all I'd suggest you to look at your caching strategy and check it.

As per your question regarding memory statistics and notifications, you shouldn't be doing this in the code for sure. Monitoring must be setup on hosting infrastructure. If that's VM or physical server - check Windows counters. If that's Azure Web Apps - use Application insights and configure alerts. Anyway, you should not be monitoring from the same code instance, otherwise, if the whole application fails - you will never know because you "monitoring" will silently die together with the application.

1 votesVote for this answer Mark as a Correct answer

Duane Bryant answered on March 13, 2020 05:42

Thank you sir for making time to reply in such hurry .

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.