How to work with Performance counters and WCF service in IIS?

后端 未结 2 806
-上瘾入骨i
-上瘾入骨i 2021-01-05 09:44

Hi,

I have a WCF service in IIS7 that communicates with a winform application over TCP(WAS), now I need to monitor the performance.

I have a

相关标签:
2条回答
  • 2021-01-05 09:55

    WCF services includes performance counters that you can track with the Windows Performance Monitor (Perfmon.exe). You can launch this from the Administrative Tools in Windows Server 2003.

    Performance counters can be enabled from the diagnostics section of the .config file for the service, as shown in the following sample configuration:

    <configuration>
      <system.serviceModel>
        <diagnostics performanceCounters="All" /> 
      </system.serviceModel>
    </configuration>
    

    You may want to check out these articles which can guide you on how to use the performance counters for WCF services:

    • MSDN - WCF Performance Counters
    • MSDN - Using Performance Counters
    • How to use performance counters to diagnose performance of WCF applications
    0 讨论(0)
  • 2021-01-05 10:01

    It looks like this might be a bug (or a design-feature) with how performance counters work. After some poking, I've found this on the MSDN forums:

    I have the same problem. It appears that Microsoft truncates the tail end of the operation name when naming the counter instance. They replace the truncated part with some sort of 2-digit base-10 magic number. I'm guessing it's a hash, but who knows how it's actually generated. The rub is that this number is not guaranteed unique and can cause collisions in counter names. If such a collision happens, it seems to cause all Endpoint and Operation counters to vanish (at least for me).

    I have two methods named UpdateMarkupChunk and UpdateMarkupCancel. If I comment out one or the other so that the other doesn't exist, they both resolve to UpdateMarkupC53 in the counter instance name. When I comment them both in, none of the counter instances appear for ServiceModelEndpoint or ServiceModelOperation.

    Can you suggest a workaround for this, Microsoft? I have a production service already in place that I would like to monitor, and changing the operation names is not an option.

    And Microsoft responded with:

    You are correct. And this behaviour is by design. There is a limit on the length of a performance counter instance's name.

    Operation performance counters are found under the ServiceModelOperation 4.0.0.0 performance object when viewing with the Performance Monitor (Perfmon.exe). Each operation has an individual instance. That is, if a given contract has 10 operations, 10 operation counter instances are associated with that contract. The object instances are named using the following pattern:

    (ServiceName).(ContractName).(OperationName)@(first endpoint listener address)

    When a Windows Communication Foundation (WCF) counter instance name exceeds the maximum length, WCF replaces a portion of the instance name with a hash value.

    So it seems because of this maximum name limitation, the large chances of a hash collision when there's only a two-digit hash suffix, and that when two instances of a counter have the same name, it wipes out the entire counter that it's not actually possible.

    Which is more than a little frustrating. So unless Microsoft fixes this problem (either long hash values, or better collision handling by perf counters), or provides a suitable workaround we are working blind.

    0 讨论(0)
提交回复
热议问题