1 / 56

DEV411 ASP.NET: Best Practices For Performance

DEV411 ASP.NET: Best Practices For Performance. Stephen Walther www.SuperexpertTraining.com. Purpose of Talk. What is the fastest method of displaying a set of database records in an ASP.NET Page?. Testing Tools. Trace Tools Profiler Tools Load Tools. Trace Tools.

tuwa
Télécharger la présentation

DEV411 ASP.NET: Best Practices For Performance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DEV411 ASP.NET: Best Practices For Performance Stephen Walther www.SuperexpertTraining.com

  2. Purpose of Talk What is the fastest method of displaying a set of database records in an ASP.NET Page?

  3. Testing Tools • Trace Tools • Profiler Tools • Load Tools

  4. Trace Tools • ASP.NET Page or Application Tracing Display trace information on page • System.Diagnostics Tracing Write trace information tocustom listener

  5. Trace Tools

  6. Profiler Tools • CLR Profiler Free Profiler from Microsoft • ANTS Profiler Available at www.Red-Gate.com • SQL Profiler Included with Microsoft SQL Server

  7. ANTS Profiler

  8. Load Tools • Application Center Test Included with Visual Studio .NET Enterprise • Web Application Stress Tool (WAST) Free download from Microsoft site • ANTS Load Available at www.Red-Gate.com. Includes calculated Frustration Coefficient

  9. Test Setup • Application Center Test (ACT) • .NET Framework 1.1 • SQL Server 2000 • Windows Server 2003 (Standard)

  10. Performance Statistics • Requests Per Second (RPS) • Time To Last Byte (TTLB) • Page Execution Time

  11. Timer Module The Timer Module records the time interval between • PreRequestHandlerExecute Event • PostRequestHandlerExecute Event

  12. Timer Module BeginRequest PreRequestEventHandlerExecute Application Events Init Load Page Events Unload PostRequestEventHandlerExecute EndRequest TimerModule.cs

  13. Clock Resolution QueryPerformanceCounter is accurate to 1/3579545 of a second or about a millionth of a second

  14. The Test • Request page 1050 times • Discard first 50 requests • Log time of each request • Average results

  15. Database Setup Four Database Tables • Products10 – 10 Rows • Products50 – 50 Rows • Products100 – 100 Rows • Products500 – 500 Rows

  16. What’s Faster? • DataReader • DataSet DisplayDataReader.aspx DisplayDataSet.aspx

  17. DataReader

  18. DataSet

  19. DataReader Versus DataSet

  20. DataReader Versus DataSetFinal Results On average, a DataReader is 16% faster than DataSet

  21. 3rd Option – ArrayList Using an ArrayList instead of a DataReader results in similar performance with the advantages of a static representation of data DisplayArrayList.aspx

  22. ArrayList

  23. What’s Faster? • SqlDataReader • OleDbDataReader

  24. OleDbDataReader

  25. OleDbDataReaderFinal Results On average, a SqlDataReader is 115% faster than an OleDbDataReader

  26. What’s Faster? • Inline SQL • Stored Procedure

  27. Stored Procedure

  28. What’s Faster? DataReader Column Reference • By Name: Response.Write(dr[“ProductName”]); • By Ordinal: Response.Write(dr[0]); • By GetString(): Response.Write(dr.GetString(0));

  29. Column Reference

  30. Column ReferenceFinal Results On average, ordinal reference is 11% faster than by name

  31. What’s Faster? • Proper Case dr[“ProductName”] • Improper Case dr[“PRODUCTNAME”]

  32. Proper Case

  33. Proper CaseFinal Results Using proper column case is 1% faster than improper column case

  34. What’s Faster? • Inline • ASP.NET Controls

  35. DataGrid

  36. DataGridFinal Results • Inline script is 233% faster than a DataGrid

  37. What’s Faster? • DataGrid with ViewState Disabled • DataGrid with ViewState Enabled

  38. ViewState

  39. ViewStateFinal Results DataGrid with ViewState disabled is 66% faster than DataGrid with ViewState enabled

  40. What’s Faster? • AutoGenerateColumns • Template Columns

  41. Template Columns

  42. Template ColumnsFinal Results A DataGrid without templates is 39% faster than a DataGrid with templates

  43. What’s Faster? How to improve template performance? • DataBinder.Eval <%# DataBinder.Eval(Container.DataItem, “ProductName”) %> • Explicit Cast <%# ((DbDataRecord)Container.DataItem)["ProductName"]%> • ItemDataBound void ItemDataBound(Object s, DataGridItemEventArgs e) DisplayItemDataBound.aspx

  44. Template Performance

  45. Template PerformanceFinal Results Explicit cast is 11% faster than using a databinding expression

  46. Creating A Custom Control Would a custom DataGrid (with severely reduced functionality) be faster than the standard DataGrid? FastGrid.cs

  47. Custom Control

  48. Custom ControlFinal Results FastGrid is 37% faster than astandard DataGrid

  49. What’s Faster? • DataGrid with no caching • DataGrid with data caching • DataGrid with output caching

  50. Data Caching

More Related