According to this question, I want to know if asp.net’s system.web.caching.cache is good for me, or I should use database caching?
So, I need to know how much memory is being used by system.Web.caching.cache?
But since I am using a shared hosting server, I can’t use task manager.
Is there any way to determine how much memory is used by system.web.caching.cache using some code?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
One fast way to see how many working memory your application use is to direct ask the garbage collection.
long bytes = GC.GetTotalMemory(false); txtMemoryUsed.Text = bytes.ToString();
and use this literal <asp:Literal runat="server" ID="txtMemorysUsed" EnableViewState="false" />
But you can get more details using the PerformanceCounter, for example you can get how many virtual memory the pools used by this code:
var oPerfCounter = new PerformanceCounter(); oPerfCounter.CategoryName = "Process"; oPerfCounter.CounterName = "Virtual Bytes"; oPerfCounter.InstanceName = "aspnet_wp"; txtMemorysUsed.Text = "Virtual Bytes: " + oPerfCounter.RawValue + " bytes";
You can use all this parameters to get information’s for your pool.
Processor(_Total)% Processor Time Process(aspnet_wp)% Processor Time Process(aspnet_wp)Private Bytes Process(aspnet_wp)Virtual Bytes Process(aspnet_wp)Handle Count Microsoft® .NET CLR Exceptions# Exceps thrown / sec ASP.NETApplication Restarts ASP.NETRequests Rejected ASP.NETWorker Process Restarts (not applicable to IIS 6.0) MemoryAvailable Mbytes Web ServiceCurrent Connections Web ServiceISAPI Extension Requests/sec
for example, this parametres get the cpu load.
oPerfCounter.CategoryName = "Processor"; oPerfCounter.CounterName = "% Processor Time"; oPerfCounter.InstanceName = "_Total"; txtOutPut.Text = "Current CPU Usage: " + oPerfCounter.NextValue() + "%";
reference: http://msdn.microsoft.com/en-us/library/ms972959.aspx
relative: Monitoring ASP.NET application memory from within the application
I have test that on local iis and works.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0