开发者

Measure the time spent in each layer of a Web Service

I have a WCF REST Web Service (.NET 4) which is design based on multitier architecture (i.e. presentation, logic, data access, etc.). At runtime and withou开发者_StackOverflow社区t instrumentation, I would like to measure how much time a single request takes for each layer (e.g. Presentation = 2 ms, Logic = 50 ms, Data = 250 ms).

Considering that I cannot change the method signature to pass in a StopWatch (or anything similar), how would you accomplish such thing?

Thanks!


If you cannot add code to your solution, you will end up using profilers to examine what the code is doing, but I would only suggest that in an environment other than production unless you are only having issues in performance. There are plenty of ways to set up another environment and profile under load.

Profilers will hook into your code and examine how long each method takes. There is no "this is the business layer performance" magic, as the profiler realizes physical boundaries (class, method) instead of logical boundaries, but you can examine the output and determine speed.

If you can touch code there are other options you can add which can be turned on and off via configuration. Since you have stated you cannot change code, I would imagine this is a non-option.


There's a tracer in the MS Ent Libs, syntaxically you use a using statement and duration of everything that occurs inside the using statement is logged into the standard Ent Lib logging ecosystem.

using(new Tracer()) { // Your code here. }

More basic info on MSDN here, and see here for it's constructors; there are different constructors that allow you to pass in different identifiers to help you keep track of what's being recorded.


I've recently been working on performance-enhancements and looking at .NET performance tools. DotTrace seems to be the best candidate so far.

In particular, the Performance Profiler can produce Tracing Profiles. These profiles detail how long each method is taking:

Tracing profiling is a very accurate way of profiling that involves getting notifications from CLR whenever a function is entered or left. The time between these two notifications is taken as the execution time of the function. Tracing profiling helps you learn precise timing information and the number of calls on the function level.

This screen-shot illustrates the useful stats that the tool can produce:

Measure the time spent in each layer of a Web Service

You should be able to see exactly how much time a single request takes for each layer by inspection of the profiling data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜