Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the performance hit of Performance Counters

When considering using performance counters as my companies' .NET based site, I was wondering how big the overhead is of using them.

Do I want to have my site continuously update it's counters or am I better off to only do when I measure?

like image 717
Boaz Avatar asked Nov 14 '08 16:11

Boaz


People also ask

What is a counter performance?

Counter-performance in Europe Counter-performance (in European Private Law) In this context, this may be a concept of the term: A "counter-performance" is a performance which is due in exchange for another performance.

What is the use of performance counter?

Windows Performance Counters provide a high-level abstraction layer that provides a consistent interface for collecting various kinds of system data such as CPU, memory, and disk usage. System administrators often use performance counters to monitor systems for performance or behavior problems.


2 Answers

The overhead of setting up the performance counters is generally not high enough to worry about (setting up a shared memory region and some .NET objects, along with CLR overhead because the CLR actually does the management for you). Here I'm referring to classes like PerformanceCounter.

The overhead of registering the perfromance counters can be decently slow, but generally is not a concern because it is intended to happen once at setup time because you want to change machine-wide state. It will be dwarfed by any copying that you do. It's not generally something you want to do at runtime. Here I'm referring to PerformanceCounterInstaller.

The overhead of updating a performance counter generally comes down to the cost of performing an Interlocked operation on the shared memory. This is slower than normal memory access but is a processor primitive (that's how it gets atomic operations across the entire memory subsystem including caches). Generally this cost is not high to worry about. It could be 10 times a normal memory operation, potentially worse depending on the update and what contention is like across threads and CPUs. But consider this, it's literally impossible to do any better than interlocked operations for cross-process communication with atomic updates, and no locks are held. Here I refer to PerformanceCounter.Increment and similar methods.

The overhead of reading a performance counter is generally a read from shared memory. As others have said, you want to sample on a reasonable period (just like any other sampling) but just think of PerfMon and try to keep the sampling on a human scale (think seconds instead of milliseconds) and you proably won't have any problems.

Finally, an appeal to experience: Performance counters are so lightweight that they are used everywhere in Windows, from the kernel to drivers to user applications. Microsoft relies on them internally.

Advice: The real question with performance counters is the learning curve in understanding (which is moderate) and one measuring the right things (seems easy but often you get it wrong).

like image 81
EWizard Avatar answered Sep 21 '22 02:09

EWizard


The performance impact is negligible in updating. Microsoft's intent is that you always write to the performance counters. It's the monitoring of (or capturing of) those performance counters that will cause a degradation of performance. So, only when you use something like perfmon to capture the data.

In effect, the performance counter objects will have the effect of only "doing it when you measure."

like image 43
dpurrington Avatar answered Sep 19 '22 02:09

dpurrington