c# - PerformanceCounter creation take a LONG time -


i'm working on charge balancing system , need know charge of each machine. performancecounter seem way go, creating first 1 take between 38 , 60 sec. each subsequent new counter or 'nextvalue' call instant however.

here code i'm using :

[testclass] public class perfmon {     [testmethod]     public void simplecreationtest()     {         stopwatch time = new stopwatch();         time.start();         debug.writeline("time : " + time.elapsedmilliseconds);          // create          performancecounter ram = new performancecounter("memory", "available mbytes");         debug.writeline("time : " + time.elapsedmilliseconds + " => ram created");          performancecounter cpu = new performancecounter("processor", "% processor time", "_total");         debug.writeline("time : " + time.elapsedmilliseconds + " => cpu created");          performancecounter gc = new performancecounter(".net clr memory", "% time in gc", "_global_");         debug.writeline("time : " + time.elapsedmilliseconds + " => gc created");          // read          float value = ram.nextvalue();         debug.writeline("time : " + time.elapsedmilliseconds + " => ram value : " + value);          value = cpu.nextvalue();         debug.writeline("time : " + time.elapsedmilliseconds + " => cpu value : " + value);          value = gc.nextvalue();         debug.writeline("time : " + time.elapsedmilliseconds + " => gc value : " + value);     } } 

research

performancecounter extremely slow in connecting remote server

creating new system.diagnostics.performancecounter slow

i tried using other constructors , giving precise 'machinename' doesn't change anything.

why call performancecounter slow?

http://craigandera.blogspot.fr/2005/06/performancecounter-constructor-horribly_21.html

according 2 threads, problem seem fact performance counters shared resource. don't understand how solve that.

running visual studio in administrator 'accelerate' first creation 38 sec 26 sec, doesn't solve problem either.


thanks help.

i tried code on machine , got >2.5 seconds constructor of performancecounter. not able debug .net source code (i'm running vs2013 express edition, windows 7 64b) did series of experinets:

  1. i called default constructor of performancecounter. executes instantly.
  2. using perfmon checked networking related activity. saw nothing peculiar.
  3. i monitored memory footprint. saw when calling first parametrized constructor add ~2.5mb memory footprint of code.
  4. using perfmon checked if there's spike in count of used mutex, semaphores , other synchronization objects. nothing unusual happened.
  5. i tested code in various times while different number of processes active. saw there great variation. 1.4 seconds, 2.7 5 seconds.
  6. i opened gui monitoring session , ran code saw no gain.

so believe there no setup problem , the answer performancecounter constructor complex work takes lot of time execute.

all events being monitored software events, can tracked operating system. suppose when new performancecounter object created, the os has generate current state of machine. possibly means getting information processes, , of all, storing information readable , fast accessible structure. observed that more active processes have, slower performancecounter created. more cores have, more data have collect.

in last link sent, there's comment seems validate theory suppose spinlock part optimized since 2005. measure of last resort debug .net source constructing performancecounter. think how it's implemented.

what creating performancecounter objects need during initialization phase of application.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -