Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Planning, testing and tuning for ASP.NET and IIS 6.0

0.00/5 (No votes)
11 Jan 2005 1  
An approach to proactive IIS 6.0 server management and ASP.NET performance tuning and testing. We will look at editing the Metabase for expanding the use of GZip, at threading, at compression, at security, IIS 6.0 object cache, and a host of other topics.

So let us take advantage of performance testing/tuning
and then alter some settings for Windows 2003/IIS 6.0.

Unfortunately where to start a testing and tuning process can be driven by who has the biggest issues first.  Would it be the Server Admin, the Architect, the Developer, or the user who experiences a slow-down?  If there is a large out-cry from users, or you expect traffic to rapidly expand with a new roll-out, you may not want to be caught off guard by not being proactive.

Possibly all of you may want to go through some ASP.NET Performance Checklists with your staff:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/ScaleNetCheck03.asp

A short list of topics from the above link include:

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

Resource Management

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

Pages

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

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.

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.

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.

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.

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

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.


Of course you are going to need a "MS Web Application Stress Tool" for some testing: http://www.microsoft.com/technet/archive/itsolutions/intranet/downloads/webstres.mspx

Then you can begin to chart out and then tune your .NET applications performance: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt16.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt17.asp

Then you can begin to take this information and compare it against the many ASP.NET How To documents:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenethowto.asp

Topics include:

  1. "How To: Improve Serialization Performance"
  2. "How To: Monitor the ASP.NET Thread Pool Using Custom Counters"
  3. "How To: Optimize SQL Indexes"
  4. "How To: Optimize SQL Queries"
  5. "How To: Page Records in .NET Applications"
  6. "How To: Perform Capacity Planning for .NET Framework Applications"
  7. "How To: Scale .NET Applications"
  8. "How To: Submit and Poll for Long-Running Tasks"
  9. "How To: Time Managed Code Using QueryPerformanceCounter and QueryPerformanceFrequency"
  10. "How To: Use ACT to Test Performance and Scalability"
  11. "How To: Use ACT to Test Web Services Performance"
  12. "How To: Use Custom Performance Counters from ASP.NET"
  13. "How To: Use the CLR Profiler"
  14. "How To: Use EIF"
  15. "How To: Use the SQL Profiler"

See also http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/webapp/iis/iis6perf.mspx

1) So let's try some things out and retest after implementation.

GZip - IIS 6.0: While the benefit will be for Firefox and IE 6.0 browser users for now it is worth your attention.  Do note though that Gzip gains are in bandwidth and as gains in "perceived" speed of page loads. It could also help reduce the amount of bytes sent by the server, so for high volume servers this could yield more sizable results.  Also note CPU utilization spikes may result.

For more details see:
http://www.microsoft.com/resources/documentation/iis/6/all/proddocs/en-us/ref_mb_hcdodynamiccompression.mspx

Check your Scalability and work with GZip Headers:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt04.asp

The original specs for GZip are also sometimes useful:
http://www.ietf.org/rfc/rfc1951.txt?number=1951 and http://www.ietf.org/rfc/rfc1952.txt?number=1952

Edit the Metabase

WARNING: If you edit the metabase incorrectly, you can cause serious problems that may require you to reinstall any product that uses the metabase. Microsoft cannot guarantee that problems that result if you incorrectly edit the metabase can be solved. Edit the metabase at your own risk.

NOTE: Always back up the metabase before you edit it.

To enable IIS 5.0 to compress .aspx pages, follow these steps: 1. Open a command prompt.
2. Type net stop iisadmin, and then press ENTER.
3. Type cd C:\InetPub\adminscripts, and then press ENTER.
4. Type the following, and then press ENTER:
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
5. Type the following, and then press ENTER:
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
6. Type net start w3svc, and then press ENTER. 1

See http://support.microsoft.com/?id=322603 for more information and for other issues to help you mitigate issues.

Then see http://www.dotnetdevs.com/articles/IIS6compression.aspx by Brad Wilson for further instructions and a decent trace tool.

Enabling HTTP Compression
If your server generates a large volume of dynamic content, consider whether the additional processing cost of HTTP compression is one that you can reasonably afford. If the % Processor Time counter is already 80 percent or higher, enabling HTTP compression is not recommended.

To test HTTP compression

To establish a baseline, use System Monitor to log the % Processor Time counter of the Processor object over several days. This counter has a total instance and a separate instance for each processor in the system. (If your server has more than one processor, you should watch the individual processors as well as the total to discover any imbalance in the workload.) Additionally, you should log the Bytes Sent/sec counter of the Network Interface object.
Enable compression and continue to log the value of these counters for an extended period, preferably for several days, so you have a good basis for comparison.
Compare the values with and without compression.
Note If you see signs of blocking or bottlenecking during the test, you should promptly stop the test. A significant drop in the value of either counter indicates that performance with compression enabled has decreased relative to performance without compression enabled.

Important You must be a member of the Administrators group on the local computer to perform the following procedure (or procedures), or you must have been delegated the appropriate authority. As a security best practice, log on to your computer using an account that is not in the Administrators group, and then use the Run as command to run IIS Manager as an administrator. From the command prompt, type runas /user:administrative_accountname "mmc %systemroot%\system32\inetsrv\iis.msc".

To enable HTTP compression

  1. In IIS Manager, expand the local computer, right-click the Web Sites folder, and then click Properties.
  2. Click the Service tab, and in the HTTP compression section, select the Compress application files check box to compress application files.
  3. Select the Compress static files check box to compress only static files for transmission to compression-enabled clients.
  4. In the Temporary directory box, type the path to a local directory or click Browse to locate a directory. Compressed files are kept in this temporary directory. The directory must be on a local drive on an NTFS-formatted partition. The directory cannot be a compressed directory and should not be shared.
  5. Under Maximum temporary directory size, click a folder size option. If you click the Limited to (in megabytes) option and enter a number in the text box next to it, IIS automatically cleans up the temporary directory according to a "least recently used" rule when the set limit is reached.
  6. Click Apply, and then click OK. 2

http://www.microsoft.com/resources/documentation/WindowsServ/2003/standard/proddocs/en-us/Default.asp?url=/resources/documentation/WindowsServ/2003/standard/proddocs/en-us/qos_utilbandwdth.asp

2) Caching, Threads, and SSL- They gave you more in IIS 6.0 so why not use it and tweak it? (Some of the "Highlights".)

"Windows Server 2003 and IIS 6.0 provide kernel caching. ASP.NET pages can automatically benefit from the IIS 6.0 kernel cache. Kernel caching produces significant performance gains because requests for cached responses are served without switching to user mode." 3


Recommended Threading Settings for Reducing Contention used when

  • You have available CPU.
  • Your application performs I/O bound operations such as calling a Web method or accessing the file system.
  • The ASP.NET Applications/Requests In Application Queue performance counter indicates that you have queued requests.

Configuration setting

Default value
(.NET Framework 1.1)
Recommended value
maxconnection
2
12 * #CPUs
maxIoThreads
20
100
maxWorkerThreads
20
100
minFreeThreads
8
88 * #CPUs
minLocalRequestFreeThreads
4
76 * #CPUs


Trim Your Page's "K" size to regain bandwidth

Processing large page sizes increases the load on the CPU, increases the consumption of network bandwidth, and increases the response times for clients. Avoid designing and developing large pages that accomplish multiple tasks, particularly where only a few tasks are normally executed for each request. Where possible logically partition your pages.

To trim your page size, you can do one or all of the following:

  • Use script includes for any static scripts in your page to enable the client to cache these scripts for subsequent requests. The following script element shows how to do this.
    <script language=jscript src="scripts\myscript.js">

  • Remove characters such as tabs and spaces that create white space before you send a response to the client. Removing white spaces can dramatically reduce the size of your pages (Especially on pages with several hundred lines.  Yes it can be harder to read the source, but save your eyes as well by using an editor on these big ones). The following sample table contains white spaces.
    // with white space
    <table>
          <tr>
                      <td>hello</td>
                      <td>world</td>
           </tr>
    </table>

  • The following sample table does not contain white spaces.
    // without white space
    <table>
    <tr><td>hello</td><td>world</td></tr>
    </table>

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt06.asp -- other optimizations are contained within.

Retime the IIS Object Cache 4

Consider shortening the period of time that an unused object remains in the cache, or lengthening the time that a used object remains in the cache, by adding the ObjectCacheTTL entry to the registry.

Caution

Do not edit the registry unless you have no alternative. The registry editor bypasses standard safeguards, allowing settings that can damage your system, or even require you to reinstall Windows. If you must edit the registry, back it up first and see the Registry Reference on the Windows Server 2003 Resource Kit companion CD or on the Web at http://www.microsoft.com/reskit.
The value of ObjectCacheTTL controls the static file cache by specifying the Time To Live (TTL), which sets the length of time that objects are held in cached memory. If an object in the memory cache has not been referenced for the defined period, that object is phased out of the cache.
The default value is 30 seconds. If system memory is limited or if the contents of the server are dynamic, you can use a lower TTL to prevent system memory from being used to cache a large number of volatile objects. Setting the ObjectCacheTTL entry to unlimited disables the object-cache scavenger and allows cached objects to remain in the cache until the cached object changes. Disabling the cache scavenger is useful if your server has ample system memory and your data is relatively static.
Use the following procedure to reset the time that an unused object remains in the object cache by adding the ObjectCacheTLL entry to the registry.

Important

You must be a member of the Administrators group on the local computer to run scripts and executables, or you must have been delegated the appropriate authority. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run your script or executable as an administrator. At a command prompt, type runas /profile /User:MyMachine\Administrator cmd to open a command window with administrator rights and then type cscript.exe ScriptName (including the full path with parameters, if any).

To reset the period that unused objects remain in the cache 4

1. From the Start menu, click Run, type regedit.exe, and then click OK.
2. In the registry editor, navigate to the following subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\InetInfo\Parameters
3. Right-click the Parameters subkey, point to New, and then click DWORD Value.
4. In the New Value box, type ObjectCacheTTL
5. Right-click ObjectCacheTTL, and then click Modify.
6. Under Base, click Decimal.
7. In the Value Data box, type the number of seconds that you want an unused object to remain in the cache, and then click OK.
The default value is 30 (seconds). You can enter any value from zero, to disable caching, through 4,294,967,295 (unlimited), to disable the object-cache scavenger and allow cached objects to remain in the cache until the cached object changes.

Change the Balance of the File System Cache to the IIS 6.0 Working Set

By default, servers running Windows Server 2003 are configured to give preference to the file system cache over the working sets of processes when allocating memory (through the server property Maximize data throughput for file sharing). Although IIS 6.0�based servers benefit from a large file system cache, giving the file system cache preference often causes the IIS 6.0 pageable code to be written to disk, which results in lengthy processing delays. To avoid these processing delays, set server properties to maximize data throughput for network applications.

To maximize data throughput on the server for network applications 4

1. In Control Panel, double-click Network Connections, right-click Local Area Connection, and then click Properties.
2. Select File and Printer Sharing for Microsoft Networks, and then click Properties.
3. Under Optimization, select Maximize data throughput for network applications.

Limit Connections

If your server does not have enough memory, limiting the number of connections on the server might help alleviate the shortage because some physical memory (about 10 KB per connection) is consumed by the data structures that the system uses to keep track of connections. For more information about limiting connections to save memory, see �Limiting Connections to Manage Resources� earlier in this chapter.
Limit the Queue Length for Application Pools

If you are running your server in worker process isolation mode, you can limit application pool queue lengths to prevent large numbers of requests from queuing up and overloading your server. When the queue length limits feature is enabled (it is enabled by default), IIS monitors the number of requests in a designated application pool queue before queuing a new request. Use IIS Manager to change the default limit of 1,000 requests for application pool request queues.

If adding a new request to the queue exceeds the maximum queue length, the server rejects the request and sends a 503 error (Server Too Busy) to the client. However, requests that are already queued remain queued even if the limit is changed to a value that is less than the current queue length.

Use the following procedure to set a limit on the queue length for an application pool. 4

Important
You must be a member of the Administrators group on the local computer to perform the following procedure or procedures, or you must have been delegated the appropriate authority. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type
runas /User:Administrative_AccountName �mmc %systemroot%\system32\inetsrv\iis.msc�.

To change an application pool�s queue length limit
1. In IIS Manager, expand the local computer, expand the Application Pools folder, right-click the application, and then click Properties.
2. On the Performance tab, under Request queue limit, select the Limit the kernel request queue to check box.
3. In the requests box, type or select the maximum number of queued requests to allow. The default limit is 1,000 requests.

Important If you clear the Limit the kernel request queue to check box, IIS does not apply a request limit. Without a limit, IIS might queue requests until your server runs out of memory.

4. Click Apply, and then click OK.

For information about configuring application pool queue length limits by using metabase properties, see the AppPoolQueueLength property in the �Metabase Property Reference� in IIS 6.0 Help.

Adjust Resource Allocation in Windows 4

System processing is managed by Windows Server 2003, which can allocate processor and memory resources among tasks. If your server needs a temporary performance boost, you can temporarily adjust resource allocation in Windows to allocate the resources where you need them:
# To obtain a faster response time, you can set Windows to allocate more processor time to the program that you are currently running.
# If you want to run background programs, such as printing or disk backup, while you work, you can have Windows share processor resources equally between background and foreground programs.

For more information about changing the way that Windows allocates processor resources, see �Change the performance of foreground and background programs� in Help and Support Center for Windows Server 2003.
Limit Performance Logging

Always keep in mind that performance logging uses system resources. When you are not actively checking performance, disable performance-related logging to squeeze a bit more performance from your server. 4


Configuring ServerCacheTime for SSL Sessions 4

If you plan to support long SSL sessions, consider lengthening the SSL cache time-out interval by adding the ServerCacheTime entry to the registry. If you expect thousands of users to connect to your site by using SSL, estimate how long you expect SSL sessions to last, and then set the value of the ServerCacheTime entry to a number slightly higher than your estimate. Do not set the value much higher than your estimate, because the resulting time-out interval might cause your server to retain stale data in the cache.

Caution
The registry editor bypasses standard safeguards, allowing settings that can damage your system, or even require you to reinstall Windows. If you must edit the registry, back it up first and see the Registry Reference on the Windows Server 2003 Resource Kit companion CD or on the Web at http://www.microsoft.com/reskit.
One reason for changing the default value for the SSL session cache is to force the client to authenticate more often. More frequent caching is sometimes useful, for example, if you know that the client is using a smart card and you want the Web page to be accessible only when the user inserts the smart card in the reader.
Before changing the SSL cache time-out interval, make sure that HTTP Keep-Alives are enabled (HTTP Keep-Alives are enabled by default). SSL sessions do not expire when you use them with HTTP Keep-Alives except when the browser closes the connection.

Important
You must be a member of the Administrators group on the local computer to run scripts and executables, or you must have been delegated the appropriate authority. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run your script or executable as an administrator.
At a command prompt, type

runas /profile /User:MyMachine\Administrator cmd

to open a command window with administrator rights and then type

cscript.exe ScriptName (including the full path with parameters, if any).

To configure the ServerCacheTime registry entry 4

1. From the Start menu, click Run, type regedit.exe, and then click OK.
2. In the registry editor, navigate to the following subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL.
3. Right-click the SCHANNEL subkey, point to New, and then click DWORD Value.
4. In the New Value box, type the following: ServerCacheTime
5. Right-click the ServerCacheTime entry and then click Modify.
6. Under Base, click Decimal.
7. In the Value Data box, type the value (in milliseconds) that you want to assign for the cache time (1 minute = 60,000 milliseconds), and then click OK.

Commonly used cache times converted to milliseconds 4

Desired Cache Time
(1 minute = 60,000 milliseconds)
ServerCacheTime Value
(in Milliseconds)
No secure session caching
0 (turns off session caching)
2 minutes (default setting for the Microsoft� Windows NT� version 4.0 operating system)
120000
5 minutes (default setting for the Microsoft� Windows� 2000 operating system)
300000
10 hours (default setting for Windows Server 2003, Windows 2000 with Service Pack 2 [SP2] or later, and Windows XP)
36000000
For more information about configuring SSL session caching, including how to set the ClientCacheTime registry setting, see article 247658, �Configure Secure Sockets Layer Server and Client Cache Elements,� in the Microsoft Knowledge Base. To find this article, see the Microsoft Knowledge Base link on the Web Resources page at http://www.microsoft.com/windows/reskits/webresources.

 

http://download.microsoft.com/download/7/4/f/74fe970d-4a7d-4034-9f5d-02572567e7f7/19_CHAPTER_6_Optimizing_IIS_6.0_Performance.doc  <<<----- The full book is located at: http://www.microsoft.com/downloads/details.aspx?FamilyID=80a1b6e6-829e-49b7-8c02-333d9c148e69&DisplayLang=en#filelist and will provide your Server Admin and those concerned with managed code with a lot of great "bed-side reading".  ;-I

By now you should have a good list of things to consider, code to implement, settings to change, and a lot more knowledge base to make proactive decisions from.

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here