Wednesday, March 28, 2007

ASP.Net Optimization


















































Design Considerations



  • Consider security and performance.
  • Partition your application logically.
  • ...

Threading



  • Tune the thread pool by using the formula to reduce contention.
  • Consider minIoThreads and minWorkerThreads for burst load.
  • ...

Server Controls




  • Identify the use of view state in your server controls.
  • Use server controls where appropriate.
  • Avoid creating deep hierarchies of controls.

Data Binding



  • Avoid using Page.DataBind.
  • Minimize calls to DataBinder.Eval.

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 single-threaded apartment (STA) COM objects in application state.

Session State



  • Prefer basic types to reduce serialization costs.
  • Disable session state if you do not use it.
  • Avoid storing STA COM objects in session state.
  • Use the ReadOnly attribute when you can.

String Management



  • Use Response.Write for formatting output.
  • Use StringBuilder for temporary buffers.

  • Use HtmlTextWriter when building custom controls.

Exception Management



  • Implement a Global.asax error handler.
  • Monitor application exceptions.
  • Set timeouts aggressively.
  • ...

Resource Management




  • Do not cache or block on pooled resources.
  • Pool resources.
  • ...

Pages



  • Trim your page size.
  • Enable buffering.
  • ...

Caching



  • Separate dynamic data from static data in your pages.

  • Cache the right data.
  • Use kernel caching on Microsoft® Windows Server™ 2003.
  • ...

State Management



  • Store simple state on the client where possible.
  • Consider serialization costs.

View State



  • Disable view state if you do not need it.

  • Minimize the number of objects you store in view state.
  • Determine the size of your view state.

HTTP Modules



  • Avoid long-running and blocking calls in pipeline code.
  • Consider asynchronous events.

COM Interop



  • Use ASPCOMPAT to call STA COM objects.
  • Avoid storing COM objects in session state or application state.

  • Avoid storing STA components in session state.
  • ...

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.
  • ...

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 Secure Sockets Layer (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.


Deployment Considerations


  • Avoid unnecessary process hops.
  • Understand the performance implications of a remote middle tier.
  • Short-circuit the HTTP pipeline.
  • 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.