ASP.NET 2.0 Performance Guidelines
From Guidance Share
Jump to navigationJump to search
- J.D. Meier, Srinath Vasireddy, Ashish Babbar, John Allen, and Alex Mackman
Design Considerations
- Consider security and performance
- Partition your application logically
- Evaluate affinity
- Reduce round trips
- Avoid blocking on long-running tasks
- Use caching
- Avoid unnecessary exceptions
Application State
- Use static properties instead of the Application object to store application state
- Use application state to share static, read-only data
- Do not store STA COM objects in application state
Caching
- Separate dynamic data from static data in your pages
- Configure the Memory Limit
- Determine the Data to Be Cached
- Refresh your cache appropriately
- Cache the appropriate form of data
- Use output caching to cache relatively static pages
- Choose the right cache location
- Use VaryBy attributes for selective caching
- Use kernel caching on Windows Server 2003
COM Interop
- Use ASPCOMPAT to call STA COM objects
- Avoid Storing COM Objects in Session State or Application State
- Avoid storing STA objects in session state
- Do not create STA objects in a page constructor
- Supplement classic ASP Server.CreateObject with early binding
Data Access
- Use paging for large result sets
- Use a DataReader for fast and efficient data binding
- Prevent users from requesting too much data
- Consider caching data
Data Binding
Exception Management
- Implement a Global.asax error handler
- Monitor application exceptions
- Use try/finally on disposable resources
- Write code that avoids exceptions
- Set timeouts aggressively
HTTP Modules
Pages
- Trim your page size
- Enable buffering
- Use Page.IsPostBack to minimize redundant processing
- Partition page content to improve caching efficiency and reduce rendering
- Ensure pages are batch compiled
- Ensure debug is set to false
- Optimize expensive loops
- Consider using Server.Transfer instead of Response.Redirect
- Use client-side validation
Resource Management
- Pool resources
- Explicitly call Dispose or Close on resources you open
- Do not cache or block on pooled resources
- Know your application allocation pattern
- Obtain resources late and release them early
- Avoid per-request impersonation
Security Considerations
- Constrain unwanted Web server traffic
- Turn off authentication for anonymous access
- Validate user input on the client
- Avoid per-request impersonation
- Avoid caching sensitive data
- Segregate Secure and Non-Secure Content
- Only use SSL for pages that require it
- Use Absolute URLs for Navigation
- Consider using SSL hardware to offload SSL processing
- Tune SSL timeout to avoid SSL session expiration
Server Controls
- Identify the use of view state in your server controls
- Use server controls where appropriate
- Avoid creating deep hierarchies of controls
Session State
- Choose Basic Types to Reduce Serialization Costs
- If You Do Not Need Session State, Disable It
- Avoid storing STA COM objects in session state
- Use the ReadOnly Attribute When You Can
State Management
String Management
- Use Response.Write for formatting output
- Use StringBuilder for temporary buffers
- Use HtmlTextWriter when building custom controls
Threading
- Tune the thread pool by using the formula to reduce contention
- Configure minIoThreads and minWorkerThreads for Burst Load
- Do Not Create Threads on a Per Request Basis
- Avoid Blocking Threads
- Avoid Asynchronous Calls Unless You Have Additional Parallel Work
View State
- If You Do Not Need View State, Disable It
- Minimize the Number of Objects You Store In View State
- Use Tracing to Analyze and Reduce the Size of Your View State
Deployment Considerations
- Avoid unnecessary process hops
- Understand the performance implications of a remote middle tier
- ASP.NET 2.0 Performance Guidelines - Deployment Considerations | Short circuit the HTTP pipeline
- ASP.NET 2.0 Performance Guidelines - Deployment Considerations | Configure the memory limit
- Disable tracing and debugging
- Ensure content updates do not cause additional assemblies to be loaded
- Avoid XCOPY under heavy load
- Consider precompiling pages
- Consider Web garden configuration
- Consider using HTTP compression
- Consider using perimeter caching
References
- See Improving ASP.NET Performance at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt06.asp