根据这个question , 我想知道 asp.net 的 system.web.caching.cache 是否适合我,还是我应该使用数据库缓存?
那么,我需要知道 system.Web.caching.cache 使用了多少内存? 但是由于我使用的是共享主机服务器,所以无法使用任务管理器。 有什么方法可以使用一些代码来确定 system.web.caching.cache 使用了多少内存?
最佳答案
查看您的应用程序使用了多少工作内存的一种快速方法是直接询问垃圾回收。
long bytes = GC.GetTotalMemory(false);
txtMemoryUsed.Text = bytes.ToString();
并使用这个文字 <asp:Literal runat="server" ID="txtMemorysUsed" EnableViewState="false" />
但是您可以使用 PerformanceCounter
获取更多详细信息,例如,您可以获得此代码使用的池的虚拟内存数量:
var oPerfCounter = new PerformanceCounter();
oPerfCounter.CategoryName = "Process";
oPerfCounter.CounterName = "Virtual Bytes";
oPerfCounter.InstanceName = "aspnet_wp";
txtMemorysUsed.Text = "Virtual Bytes: " + oPerfCounter.RawValue + " bytes";
您可以使用所有这些参数来获取池的信息。
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
例如,此参数获取 cpu 负载。
oPerfCounter.CategoryName = "Processor";
oPerfCounter.CounterName = "% Processor Time";
oPerfCounter.InstanceName = "_Total";
txtOutPut.Text = "Current CPU Usage: " + oPerfCounter.NextValue() + "%";
引用:http://msdn.microsoft.com/en-us/library/ms972959.aspx
亲戚:Monitoring ASP.NET application memory from within the application
我已经在本地 iis 上测试过并且可以正常工作。
关于c# - 确定共享主机中 asp.net 缓存使用的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10830633/