F.ASP.Net Performance Optimization

  1. Overview

    1. Summary

        1. ASP.Net performance are driven by multiple factors including hardware , security , Application Pool configuration session state , view state, Deployment architecture etc.

        2. In order to get achieve optimal performance we need to carefully understand each factor and optimize them as required

    2. Videos Tutorial

  1. ASP.Net Performance Recommendations

    1. Page and Server Control Processing

      1. Avoid unnecessary round trips to the server , use Client Callbacks Without Postbacks in ASP.NET Web Pages.

      2. Use the Page object's IsPostBack property to avoid performing unnecessary processing on a round trip

      3. Save server control view state only when necessary

      4. Leave buffering on unless you have a specific reason to turn it off

      5. Use the Transfer method of the Server object or cross-page posting to redirect between ASP.NET pages in the same application

    2. State Management

      1. Disable session state when you are not using it because it causes memory overhead and also request serialization can degrade performance in several scenario.

      2. Choose the right session-state provider for your application needs

      3. Prefer turning of View State and global level and enable only for the controls or pages that really need it.

      4. Prefer not to store any large object in view state

    1. Data Access

      1. Use SQL Server and stored procedures for data access

      2. Use the SqlDataReader class for a fast forward-only data cursor

      3. Cache data and page output whenever possible

      4. Use SQL cache dependency appropriately

      5. Use data source paging and sorting rather the UI (user interface) paging and sorting

      6. Balance the security benefit of event validation with its performance cost

      7. Avoid using view state encryption unless necessary

      8. Use SqlDataSource caching, sorting, and filtering when ever possible in case of small data sets

      9. Prefer Server side paging and sorting for large data sizes

        1. By default SQL Data Sources like ADO do paging and sorting at client side that degrade performance in case of large data set.

        2. Consider EF code first and ASP.NET 4.5 model binding

        3. Prefer QueryableDataSource or ObjectDataSource over SqlDataSource as they support server side paging and sorting.

    1. Application Configuration

      1. Consider precompiling

      2. Run Web applications out-of-process on Internet Information Services 5.0

      3. Recycle processes periodically

      4. Adjust the number of threads per worker process for your application if necessary

      5. For applications that rely extensively on external resources, consider enabling Web gardening on multiprocessor computers

      6. Disable debug mode

      7. Enable authentication only for applications that need it

      8. Configure your application to the appropriate request and response encoding settings

      9. Consider disabling AutoEventWireup for your application

      10. Remove unused modules from the request-processing pipeline.

      11. Remove any empty event handler from application particularly from global.assx

      12. Turn off runAllManagedModulesForAllRequests (RAMMFAR) whenever possible to prevent static content being accessed via ASP.Net pipeline but be careful of authentication requirements Read More...

    1. Coding Practices

        1. Do not rely on exceptions in your code Exceptions can cause performance to suffer significantly so try detecting code condition that could cause an exception

        2. Rewrite call-intensive COM components in managed code

        3. Avoid single-threaded apartment (STA) COM components

        4. Use Async/Await to increases efficient use of thread pool resources

      1. Application Architecture

      2. Prefer WebSocket for long running request because ASP.Net has 30K of overhead per request and web-socket has 10K or else prefer using SignalR

      3. Use App Suspension feature of 4.5 to increase server resource utilization.

        1. Never writes to files under c:\inetpub\wwwroot because it will overload FileSystemWatcher component that mainly keeps track of changes in application folder such as web config updated.

      4. Prefer using 32-bit vs. 64-bit processes and then creates a web-garden this will reduce memory overhead in case of large object graphs.

    1. Deployment Structure

      1. Keep ASPX files in minimum number of folders because it decreases compilation overhead.

        1. Consider enabling CDNs on ScriptManager

  1. ASP.Net Performance Monitoring

  1. ASP.Net Application Profiling

  1. How to FAQ

  1. Further Discussion

  1. Relates Tools

  1. References