简体   繁体   English

确定共享主机中asp.net缓存使用的内存

[英]Determine memory used by asp.net cache in shared hosting

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? 根据这个问题 ,我想知道asp.net的system.web.caching.cache是​​否适合我,或者我应该使用数据库缓存?

So, I need to know how much memory is being used by system.Web.caching.cache? 所以,我需要知道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? 有没有办法确定system.web.caching.cache使用一些代码使用了多少内存?

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" /> 并使用此文字<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: 但是您可以使用PerformanceCounter获取更多详细信息,例如,您可以获取此代码使用的池的虚拟内存量:

 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. 例如,此参数获取cpu负载。

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 参考: http//msdn.microsoft.com/en-us/library/ms972959.aspx

relative: Monitoring ASP.NET application memory from within the application relative: 从应用程序中监视ASP.NET应用程序内存

I have test that on local iis and works. 我在本地iis上测试并且工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM