DEV 411 ASP NET Best Practices For Performance
DEV 411 ASP. NET: Best Practices For Performance Stephen Walther www. Superexpert. Training. 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 ASP. NET Page or Application Tracing Display trace information on page System. Diagnostics Tracing Write trace information to custom listener
Trace Tools
Profiler Tools CLR Profiler Free Profiler from Microsoft ANTS Profiler Available at www. Red-Gate. com SQL Profiler Included with Microsoft SQL Server
ANTS Profiler
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
Test Setup Application Center Test (ACT). NET Framework 1. 1 SQL Server 2000 Windows Server 2003 (Standard)
Performance Statistics Requests Per Second (RPS) Time To Last Byte (TTLB) Page Execution Time
Timer Module The Timer Module records the time interval between Pre. Request. Handler. Execute Event Post. Request. Handler. Execute Event
Begin. Request Pre. Request. Event. Handler. Execute Page Events Application Events Timer Module Init Load Unload Post. Request. Event. Handler. Execute End. Request Timer. Module. cs
Clock Resolution Query. Performance. Counter is accurate to 1/3579545 of a second or about a millionth of a second
The Test Request page 1050 times Discard first 50 requests Log time of each request Average results
Database Setup Four Database Tables Products 10 – 10 Rows Products 50 – 50 Rows Products 100 – 100 Rows Products 500 – 500 Rows
What’s Faster? Data. Reader Data. Set Display. Data. Reader. aspx Display. Data. Set. aspx
Data. Reader
Data. Set
Data. Reader Versus Data. Set
Data. Reader Versus Data. Set Final Results On average, a Data. Reader is 16% faster than Data. Set
3 rd Option – Array. List Using an Array. List instead of a Data. Reader results in similar performance with the advantages of a static representation of data Display. Array. List. aspx
Array. List
What’s Faster? Sql. Data. Reader Ole. Db. Data. Reader
Ole. Db. Data. Reader
Ole. Db. Data. Reader Final Results On average, a Sql. Data. Reader is 115% faster than an Ole. Db. Data. Reader
What’s Faster? Inline SQL Stored Procedure
Stored Procedure
What’s Faster? Data. Reader Column Reference By Name: Response. Write(dr[“Product. Name”]); By Ordinal: Response. Write(dr[0]); By Get. String(): Response. Write(dr. Get. String(0));
Column Reference
Column Reference Final Results On average, ordinal reference is 11% faster than by name
What’s Faster? Proper Case dr[“Product. Name”] Improper Case dr[“PRODUCTNAME”]
Proper Case
Proper Case Final Results Using proper column case is 1% faster than improper column case
What’s Faster? Inline ASP. NET Controls
Data. Grid
Data. Grid Final Results Inline script is 233% faster than a Data. Grid
What’s Faster? Data. Grid with View. State Disabled Data. Grid with View. State Enabled
View. State
View. State Final Results Data. Grid with View. State disabled is 66% faster than Data. Grid with View. State enabled
What’s Faster? Auto. Generate. Columns Template Columns
Template Columns
Template Columns Final Results A Data. Grid without templates is 39% faster than a Data. Grid with templates
What’s Faster? How to improve template performance? Data. Binder. Eval <%# Data. Binder. Eval(Container. Data. Item, “Product. Name”) %> Explicit Cast <%# ((Db. Data. Record)Container. Data. Item)["Product. Name"]%> Item. Data. Bound void Item. Data. Bound(Object s, Data. Grid. Item. Event. Args e) Display. Item. Data. Bound. aspx
Template Performance
Template Performance Final Results Explicit cast is 11% faster than using a databinding expression
Creating A Custom Control Would a custom Data. Grid (with severely reduced functionality) be faster than the standard Data. Grid? Fast. Grid. cs
Custom Control
Custom Control Final Results Fast. Grid is 37% faster than a standard Data. Grid
What’s Faster? Data. Grid with no caching Data. Grid with data caching Data. Grid with output caching
Data Caching
Data Cache Final Results Using the data cache is 637% faster than a standard Data. Grid
Output Cache
Output Cache Final Results Using the output cache is infinitely faster than using a standard Data. Grid
Conclusions A Data. Reader is faster than a Data. Set An inline Data. Reader is faster than a Data. Grid You pay a high price for View. State Auto. Generate. Columns is faster than template columns Caching is always a good idea!
Performance Resources Microsoft Sites Performance http: //msdn. microsoft. com/netframework/using/understanding/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/intranet/downloads/webstres. mspx CLR Profiler http: //www. microsoft. com/downloads/details. aspx? Family. ID=86 ce 6052 -d 7 f 4 -4 aeb-9 b 7 a 94635 beebdda&displaylang=en ANTS Profiler and ANTS Load http: //www. Red-Gate. com
Please fill out a session evaluation on Comm. Net Q 1: Overall satisfaction with the session Q 2: Usefulness of the information Q 3: Presenter’s knowledge of the subject Q 4: Presenter’s presentation skills Q 5: Effectiveness of the presentation
- Slides: 56