What is the performance hit of Performance Counters

Viewed 13349

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?

6 Answers

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."

A performance counter is just a pointer to 4/8 bytes in shared memory (aka memory mapped file), so their cost is very similar to that of accessing an int/long variabile.

I agree with famoushamsandwich, but would add that as long as your sampling rate is reasonable (5 seconds or more) and you monitor a reasonable set of counters, then the impact of measuring is negligible as well (in most cases).

The thing that I have found is that it is not that slow for the majority of applications. I wouldn't put one in a tight loop, or something that is called thousands of times a second.

Secondly, I found that programmatically creating the performance counters is very slow, so make sure that you create them before hand and not in code.

Related