PerformanceCounters에서 '% CPU'및 '사용 가능한 메모리'를 읽는 서버에서 작업하고 있습니다. 내 개발 컴퓨터에서 잘 작동합니다. 그러나 실제 서버에서는이 두 PerformanceCounters를 읽는 것이 정말 느립니다. 적어도 처음 두 판독 동작에서.
은 아래의 코드를 수행 4~6분까지 걸릴 수 있습니다 : 내 개발 컴퓨터에이 코드를 실행하면, 그것은 (더 적은 때로는)보다 2 초에 완료됩니다PerformanceCounter에 대한 호출 속도가 느린 이유는 무엇입니까?
Stopwatch watch = new Stopwatch();
Log.Instance.Debug("Going to initialize Diagnostic's PerformanceCounters");
watch.Start();
m_CPUPerformanceCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
m_MemoryPerformanceCounter = new PerformanceCounter("Memory", "Available MBytes", true);
m_CPUPerformanceCounter.NextValue();
m_MemoryPerformanceCounter.NextValue();
//Ensure an updated value...
System.Threading.Thread.Sleep(1000);
m_CPUPerformanceCounter.NextValue();
m_MemoryPerformanceCounter.NextValue();
watch.Stop();
Log.Instance.Debug("Finished initializing Diagnosticss PerformanceCounters. Time elapsed: {0}", watch.Elapsed);
. 그러나 우리 고객의 제품을 사용해야하는 실제 서버에서는 오랜 시간이 걸릴 것입니다. 아래를 참조하십시오 :
Finished initializing Diagnosticss PerformanceCounters. Time elapsed: 00:03:59.6706860
이러한 읽기 작업 (및 나중에 '읽기'작업)이 매우 빠르게 실행되는 것이 중요합니다. 처음에도.
내 개발 컴퓨터는 Windows 7, 64 비트, 8GB RAM입니다.
클라이언트 서버는 Windows Server 2008 R2 Enterprise, 64 비트, 4GB RAM입니다.
내가 봤지만 대답을 찾을 수 없습니다. 왜 이런 일이 발생합니까? 어떻게 해결할 수 있습니까?
문제점은 무엇인지 잘 모르겠지만 다음과 같습니다. '// 업데이트 된 값을 확인하십시오 ... System.Threading.Thread.Sleep (1000);'은 값이 업데이트되도록 보장하지 않습니다. – Tarec
왜 카운터를 읽기 전용 모드로 액세스로 지정합니까? 테스트로 새로운 PerformanceCounter ("Processor", "% Processor Time", "_Total")을 시도하십시오. - 여기에 예외를 숨기지 않았습니까? 예 : UnauthorizedAccessException –
@ 타 레알 당신이 옳습니다. 그러나 필요한 경우 OS가 이러한 PerformanceCounters를 업데이트하기에 충분한 시간입니다. – m1o2