Instrumenting Your Code to Identify Performance Problems ASP.NET

You need to record the execution time of web service calls, page loads,and expensive code blocks before you can identify scalability issues.Example shows a way to calculate the execution time of a code block.

Record executing time of code block for instrumentation

private void SomeFunction( )

{

using (new TimedLog(Profile.UserName,"Some Function"))

{

...

...

}

}

You can measure the execution time of a function and a smaller block of code.Whatever is inside the using block is timed and logged, and you get an output like Example

Output from TimedLog class

6/14/2006 10:58:26 AM [email protected] SomeFunction 9.578125

The TimedLog class measures execution time of code blocks as shown in Example

The TimedLog class records the time of its creation and disposal.The execution time is the difference between these two timestamps.

public class TimedLog : IDisposable

{

private string _Message;

private long _StartTicks;

public TimedLog(string userName, string message)

{

this._Message = userName + 't' + message;

this._StartTicks = DateTime.Now.Ticks;

}

#region IDisposable Members

void IDisposable.Dispose( )

{

Debug.WriteLine(this._Message + 't' + TimeSpan.FromTicks(DateTime.Now.Ticks -

this._StartTicks).TotalSeconds.ToString( ));

}

#endregion

}

The benefit of such a log is you get a tab-delimited output, which you can use to do many types of analysis using Microsoft Excel.For example,you can generate graphs to see how the performance goes up and down during peak and nonpeak hours.You can also see whether there are high response times and determine the pattern. All these give you valuable indications of where the bottleneck is.You can also find out which calls take the most time by doing a sort on the duration column.

You can use logging utilities, such as Log4net or the Enterprise Library Logging Application Block, to log text files. Logging has a very small overhead and won’t have a significant effect on the timing of execution.

Logging the code block execution time is an invaluable tool for debugging performance issues.When you have problems with an action being timed out or taking a noticeably long time,open up the logs and analyze the average delay in the code blocks.You can then further narrow the problem down to smaller blocks of code and pinpoint which block is the culprit.It is a good idea to have a timed log added t all web service calls and business layer functions. A timed log has been added to allDash board Facade public functions.So, whenever there’s any performance issue, you can isolate the slow Facade method.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

ASP.NET Topics