开发者

How do I measure the time elapsed when calling a WCF Webservice?

开发者 https://www.devze.com 2022-12-23 20:49 出处:网络
We want to track the time taken by a web service call between a client an开发者_如何学Cd the server. This time should not include the time taken by the server to process the request.

We want to track the time taken by a web service call between a client an开发者_如何学Cd the server. This time should not include the time taken by the server to process the request. The idea is that we want to see how much time of a web service call is lost due to the actual transfer trough the network.

Does WCF already offer something in this direction?

Of course I could just add a timer on the client and subtract the server processing time but that wouldn't be very elegant.


WCF has a plethora of performance counters - see the MSDN docs on this topic or check out How to use WCF Performance Counters for a user report on how to use those.

Another option is to turn on WCF tracing - you'll get quite detailed reports as to how your messages travelled through the system, including timestamps. Based on those bits, you should be able to determine time spent on the network etc. There's a quite nice WCF Trace Viewer tool which allows you to check out those trace files quite easily.

The other option would be to use headers, e.g. DateTime fields: add a first header ("ClientOut") on the client just as the message is being sent out, and add more (e.g. "ServerIn", "ServerOut") on the server and then a last one on the client again ("ClientBackIn"). If you record the actual date/time, you should be able to look at those headers and see some information as to how much time is spent on the trip between client and server. You could create a Message Inspector extension for WCF to do something like this.


Basically, if an assessment is good enough, then a Ping test (ICMP Echo) should be enough to figure out the round-trip time for data packets between a client and a server.

But if you need strong data, you'll have to:

  1. Make sure the client and server are at sync. This can be acomplished by synchronizing both sides with a stratum-1 or stratum-2 NTP/SNTP server (see RFC 958, 1305, 1361), or implementing some other synchronization protocol.
  2. Timestamp each "message" (method call) at transmission and reception.
  3. Calculate the travel time for that message, and list it.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号