6

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?

Community
  • 1
  • 1
Mahdi Ghiasi
  • 14,873
  • 19
  • 71
  • 119

1 Answers1

6

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.NET\Application Restarts
ASP.NET\Requests Rejected
ASP.NET\Worker Process Restarts (not applicable to IIS 6.0)
Memory\Available Mbytes
Web Service\Current Connections
Web Service\ISAPI 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.

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Does GC gives me the memory used by just current Web application? – Mahdi Ghiasi May 31 '12 at 09:32
  • @Mahdi in a shared environment the pool is run many sites, your site is lives with other sites, except if you have ask for a "private" pool. (so its not just current web application, but is the pool). So you get the memory of your pool (including other sites that runs together) – Aristos May 31 '12 at 09:33
  • My control panel is plesk, and it seems that every user has an application pool. (I can stop/start it or even limit CPU usage of my sites). So, is my application pool private? – Mahdi Ghiasi May 31 '12 at 09:35
  • @Mahdi tells you only your application. – Aristos May 31 '12 at 09:35
  • @Mahdi Make many test local, and compare the results with the process monitor from sysinternals, to understand the numbers. – Aristos May 31 '12 at 09:38
  • @Mahdi I think yes must be private ! Check on the plesk say that you have a distinct pool (with a check box on the general parameters of the site) (I also have plesk on servers and there is this option) – Aristos May 31 '12 at 09:42
  • I think I have just start/stop/recycle option and CPU limiting option. – Mahdi Ghiasi May 31 '12 at 09:45
  • 1
    @Mahdi if you have this options, probably you have distinct pool to not affect others. – Aristos May 31 '12 at 09:47