Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
DEV414 Black-belt ASP.NET Tips And Tricks For Your ASP.NET Applications Rob Howard Program Manager Web Platform and Tools Team ASP.NET Community Contact [email protected] http://weblogs.asp.net/rhoward ASP.NET Resources http://www.asp.net/forums http://www.asp.net/whidbey http://www.asp.net/roadshow 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 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 Intermediate Page 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 Set Focus 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 Page Size And Duration 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 Per-Request Caching 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 Reflection Caching 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) Batched Result Set 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 Paging Data In SQL Server 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 Background Threading 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 Database Cache Invalidation 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 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.