In our last article on performance tuning, we examined how to squeeze the most performance out of an Apache server. In this installment, we’ll take a look at how to apply some of these same principles to Microsoft’s Internet Information Server (IIS), which ships as part of Windows Server.
While its percentage of the Web server market share has declined in recent years relative to Apache, IIS still remains the second most deployed Web server on the Internet. Its deep integration with Windows and host of management utilities make it a great choice for anyone hosting Web content and applications in a Windows environment. With a little performance tuning (aided, of course, by load testing), an IIS machine can perform just as well as an equivalent Apache configuration under high load.
The Usual Suspects: Compression and Connection Management
Many of the techniques a team might use to enhance IIS performance are similar to the techniques used on Apache, as they involve configuration of the HTTP protocol.
As discussed previously, enabling HTTP compression for certain files types goes a long way toward speeding up all Web server transactions. For text-based files, compression can greatly decrease the time it takes for information to travel over the wire. The Microsoft Web site has detailed information on enabling HTTP using the IIS Manager, as well as enabling and disabling the technology for specific file types.
IIS server administrators should ensure that all of their IIS servers have Keep-Alives enabled. (The setting is enabled by default.) The Connection: Keep-Alive HTTP header signals to a client that it should reuse its current connection to the server for any subsequent file requests. This prevents the client and server from engaging in the tedious (and time-consuming) process of tearing down and re-establishing a TCP connection for each image and script file contained within a Web page.
Finally, server strain can be alleviated by setting the appropriate cache control headers for static files, specifically images. Unfortunately, this is one of the few options that can’t be configured using IIS Manager. Blogger Galin Iliev has a great post on how to use the appcmd.exe command line utility to set custom cache control parameters on static images.
Use Last-Modified Caching
Last-modified caching permits IIS 6.0 and greater to serve static files from memory, instead of grabbing the latest copy from the disk. IIS accomplishes this through a simple check of the last modified date of the file: if the date on the file on the hard drive is equal to the date of the file stored in memory, IIS will serve the version it has in memory. This results in faster responses to the client by eliminating unnecessary disk I/O on the server.
Fine-Tuning Application Pools Limits
While not a performance enhancer per se, it’s important to set application pool queue-length limits correctly on an IIS server. Application pools provide an isolated worker process in which one or more URLs are executed. Incoming requests are placed in an application pool queue. If this queue grows too large, the server can run out of memory.
As noted by LunarMedia, the default size of an application pool queue is 4000, which might be tool small for a multi-processor machine and sufficient RAM. IIS admins should use trial-and-error, aided by load testing, to adjust the application pool queue-length limit to service the maximum number of requests withouts negatively impacting performance.
Using Output Caching for Web Applications
Whether you’re using PHP, ASP.NET, or classic ASP, your IIS-hosted application can benefit from Output Caching. Available only in IIS 7.0, Output Caching can be configured to cache what Microsoft calls semi-dynamic content: content (such as the contents of an online catalog) that is pulled dynamically from a data store or third-party site using an HTTP GET request, but that only changes periodically.
Semi-dynamic content can be cached based on either its query string parameters, or on its HTTP headers. After Output Caching is enabled for a page, IIS will keep track of requests for that resource, and cache its contents after it has been requested a number of times. The cache contents are invalidated after either a timeout period, or after a significant change to the underlying resource.
The IIS.Net Web site contains detailed instructions on how to enable Output Caching using the IIS Manager.
Increasing PHP Performance with FastCGI and WinCache
While IIS is typically used to host .NET application, it has gained popularity in recent years as a PHP hosting platform. Microsoft itself has encouraged the use of PHP under IIS, and has built several technologies that accelerate PHP performance on a Windows Server running IIS. Teams that deploy IIS 6.0 and above can use FastCGI, a new implementation of the CGI standard that reuses already running instances of CGI processes across many requests.
Those looking for an even greater speed boost will find it in WinCache, an IIS extension that caches compiled PHP opcode, and provides a user cache API that PHP developers can use to speed execution of their own scripts.
Also, PHP developers for Windows will be happy to know that the Zend team, which maintains PHP, worked closely with Microsoft in the development of PHP 5.3, resulting in a significant speed boost for that version of the proper programming language.
Summary
As always, when implementing performance advice, frequent and robust load testing is key. With a good load testing solution, any development team should be able to use the techniques described above to boost the performance of their IIS server, even under conditions of high use.