Title: DEV411 ASP.NET: Best Practices For Performance
1DEV411 ASP.NET Best Practices For Performance
- Stephen Walther
- www.SuperexpertTraining.com
2Purpose of Talk
- What is the fastest method of displaying a set
of database records in an ASP.NET Page?
3Testing Tools
- Trace Tools
- Profiler Tools
- Load Tools
4Trace Tools
- ASP.NET Page or Application Tracing
- Display trace information on page
- System.Diagnostics Tracing
- Write trace information tocustom listener
5Trace Tools
6Profiler Tools
- CLR Profiler
- Free Profiler from Microsoft
- ANTS Profiler
- Available at www.Red-Gate.com
- SQL Profiler
- Included with Microsoft SQL Server
7ANTS Profiler
8Load 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
9Test Setup
- Application Center Test (ACT)
- .NET Framework 1.1
- SQL Server 2000
- Windows Server 2003 (Standard)
10Performance Statistics
- Requests Per Second (RPS)
- Time To Last Byte (TTLB)
- Page Execution Time
11Timer Module
- The Timer Module records the time interval
between - PreRequestHandlerExecute Event
- PostRequestHandlerExecute Event
12Timer Module
BeginRequest
PreRequestEventHandlerExecute
Application Events
Init
Load
Page Events
Unload
PostRequestEventHandlerExecute
EndRequest
TimerModule.cs
13Clock Resolution
- QueryPerformanceCounter is accurate to 1/3579545
of a second or about a millionth of a second
14The Test
- Request page 1050 times
- Discard first 50 requests
- Log time of each request
- Average results
15Database Setup
- Four Database Tables
- Products10 10 Rows
- Products50 50 Rows
- Products100 100 Rows
- Products500 500 Rows
16Whats Faster?
DisplayDataReader.aspx
DisplayDataSet.aspx
17DataReader
18DataSet
19DataReader Versus DataSet
20DataReader Versus DataSetFinal Results
- On average, a DataReader is 16 faster than
DataSet
213rd Option ArrayList
- Using an ArrayList instead of a DataReader
results in similar performance with the
advantages of a static representation of data
DisplayArrayList.aspx
22ArrayList
23Whats Faster?
- SqlDataReader
- OleDbDataReader
24OleDbDataReader
25OleDbDataReaderFinal Results
- On average, a SqlDataReader is 115 faster than
an OleDbDataReader
26Whats Faster?
- Inline SQL
- Stored Procedure
27Stored Procedure
28Whats Faster?
- DataReader Column Reference
- By Name
- Response.Write(drProductName)
- By Ordinal
- Response.Write(dr0)
- By GetString()
- Response.Write(dr.GetString(0))
29Column Reference
30Column ReferenceFinal Results
- On average, ordinal reference is 11 faster than
by name
31Whats Faster?
- Proper Case
- drProductName
- Improper Case
- drPRODUCTNAME
32Proper Case
33Proper CaseFinal Results
- Using proper column case is 1 faster than
improper column case
34Whats Faster?
35DataGrid
36DataGridFinal Results
- Inline script is 233 faster than a DataGrid
37Whats Faster?
- DataGrid with ViewState Disabled
- DataGrid with ViewState Enabled
38ViewState
39ViewStateFinal Results
- DataGrid with ViewState disabled is 66 faster
than DataGrid with ViewState enabled
40Whats Faster?
- AutoGenerateColumns
- Template Columns
41Template Columns
42Template ColumnsFinal Results
- A DataGrid without templates is 39 faster than
a DataGrid with templates
43Whats Faster?
- How to improve template performance?
- DataBinder.Eval
- lt DataBinder.Eval(Container.DataItem,
ProductName) gt - Explicit Cast
- lt ((DbDataRecord)Container.DataItem)"ProductNa
me"gt - ItemDataBound
- void ItemDataBound(Object s, DataGridItemEventArg
s e)
DisplayItemDataBound.aspx
44Template Performance
45Template PerformanceFinal Results
- Explicit cast is 11 faster than using a
databinding expression
46Creating A Custom Control
- Would a custom DataGrid (with severely reduced
functionality) be faster than the standard
DataGrid?
FastGrid.cs
47Custom Control
48Custom ControlFinal Results
- FastGrid is 37 faster than astandard DataGrid
49Whats Faster?
- DataGrid with no caching
- DataGrid with data caching
- DataGrid with output caching
50Data Caching
51Data CacheFinal Results
- Using the data cache is 637 faster than a
standard DataGrid
52Output Cache
53Output CacheFinal Results
- Using the output cache is infinitely faster than
using a standard DataGrid
54Conclusions
- A DataReader is faster than a DataSet
- An inline DataReader is fasterthan a DataGrid
- You pay a high price for ViewState
- AutoGenerateColumns is faster than template
columns - Caching is always a good idea!
55Performance Resources
- Microsoft Sites
- Performance
- http//msdn.microsoft.com/netframework/using/under
standing/perf/default.aspx - Books
- Improving .NET Application Performance and
Scalability - http//msdn.microsoft.com/library/en-us/dnpag/html
/scalenet.asp - Software
- Web Application Stress Tool
- http//www.microsoft.com/technet/itsolutions/intra
net/downloads/webstres.mspx - CLR Profiler
- http//www.microsoft.com/downloads/details.aspx?Fa
milyID86ce6052-d7f4-4aeb-9b7a-94635beebddadispla
ylangen - ANTS Profiler and ANTS Load
- http//www.Red-Gate.com
56Please fill out a session evaluation on CommNet
Q1 Overall satisfaction with the
session Q2 Usefulness of the information Q3 Pres
enters knowledge of the subject Q4 Presenters
presentation skills Q5 Effectiveness of the
presentation