Download presentation
Presentation is loading. Please wait.
Published byRoger Hodge Modified over 8 years ago
1
DEV414 Black-belt ASP.NET Tips And Tricks For Your ASP.NET Applications Rob Howard Program Manager Web Platform and Tools Team
2
ASP.NET Community Contactrhoward@devadvice.comhttp://weblogs.asp.net/rhoward ASP.NET Resources http://www.asp.net/forumshttp://www.asp.net/whidbeyhttp://www.asp.net/roadshow
3
Agenda Building an intermediate page Set focus Outputcache (duration and page size) Per-request caching Reflection caching Returning multiple result sets SQL record paging Background processing Database cache invalidation
4
Intermediate Page Problem Long running, expensive operation Prevent Refresh or Re-Submit Display temporary ‘processing’ UI Client is still waiting for work to complete Server is still processing Perception …is not reality Client is re-activated Multiple techniques, client script easiest
5
Intermediate Page
6
Set Focus Problem Large HTML Form Set initial focus of the Form, e.g. Button Enable dynamic control selection JavaScript focus() method Use ClientID of Server Control Page.RegisterStartupScript() Script that runs when page starts
7
Set Focus
8
Duration And Page Size Problem How much data to return How large should page be Page size does affect performance Larger pages slow down server Aim for ~30K (Google is ~2K!) Duration for OutputCache More tunable than most people think Even 1Sec duration makes a difference
9
Page Size And Duration
10
Per-Request Caching Problem Data that cannot be cached Result is unique on each request Per-Request Caching Cache data for the life of a request Different than Cache API Use HttpContext.Items HttpContext is scoped to request Destroyed when request completes
11
Per-Request Caching
12
Reflection Caching Problem Reflection is powerful, but expensive 3-4 times cost of normal object creation Dynamic Class Loading Inspect or load classes at runtime Used by new Provider pattern Cache the constructor of the class 1/3 Cost of non-Cached Technique used in Forums Provider
13
Reflection Caching
14
Multiple Result Sets Problem Database operations are expensive Network IO is very costly Be as efficient as possible Use SPROCs or Parameterized SQL Batch Result Sets SqlDataReader.NextResult() Not as evident on local SQL (no network)
15
Batched Result Set
16
SQL Record Paging Problem DataGrid paging requests all records Only shows requested, discards others Return only the data you need Reduces time spent with DB Increases application throughput Stored Procedure paging Uses temporary table Requires knowledge of SQL indexes
17
Paging Data In SQL Server
18
Background Threading Problem Expensive work (index, email, updates …) Optimize the request path Schedule other tasks Use System.Threading.Timer Callback activates every n milliseconds Requires CLR AppDomain to be active Can get HttpContext – few tricks Uses thread from threadpool
19
Background Threading
20
DB Cache Invalidation Problem Keeping Cache and Database in sync Cache for period of time Optimally invalidate on data changes Built-in feature of ASP.NET 2.0 Several bad techniques for ASP.NET 1.X Uses background thread Poll for database changes Similar model used in ASP.NET 2.0
21
Database Cache Invalidation
22
Summary Tips and Tricks to make your app better Tune and optimize your application Control data from the database Off-load work Cache as much as possible
23
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.