Optimizing IIS Caching for Remote Content (IIS 6.0)
Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista
As IIS delivers content, it will cache pages in order to deliver them quickly upon subsequent requests. This is especially important with remote file servers because the network subsystem is interposed between IIS and its content, thus increasing latency. When caching is used, some mechanism must be in place for IIS to know that content on the remote server is more current than the version stored in the IIS cache.
IIS 6.0 supports two methods for determining whether the file cache needs to be updated with new content from a remote file server: last-modified time, which is new to IIS 6.0, and file change notification, as implemented in IIS 4.0 and IIS 5.0. In addition, the caching method used can be set independently for static files and ASP.
Effective with Windows Server 2003 Service Pack 1 (SP1), UNC content is cached both in the worker process file cache and in the HTTP.sys cache. The caching behavior depends on the value of the DoDirMonitoringForUnc registry property as discussed in “Last-Modified Time” and “File Change Notification” below.
By default, IIS 6.0 simply asks the file system on the file server for the last-modified time on the cached file. If the last-modified time on the file has changed, the file cache on IIS is updated with the new content. If the last-modified time has not changed, the cached version of the file on IIS is sent. By using the last-modified time instead of monitoring each virtual directory for change notifications (which can be quite expensive in terms of file system resources), scalability is increased when large numbers of virtual directories are mapped to UNC shares. Checking the last-modified time on a file is a more reliable mechanism than file change notification because some NAS devices don’t fully implement change notifications. Furthermore, security is enhanced as share and NTFS permissions are validated when the last-modified time is sampled.
The last-modified time cache method works best when:
The number of sites or virtual directories is high.
Files are large (files larger than 256K will not be cached using either caching algorithm; if you deliver larger files, the absence of the HTTP.sys cache with the last-modified time algorithm has a lower impact. In Windows Server 2003 SP1, this limit will be configurable through a registry key and may be larger than 256K).
The cache hit rate is low.
Reliability/availability is more important than performance.
Your NAS device doesn't support change notification reliably.
You're concerned about honoring the share permissions during cache hits.
On a busy server, it is impractical to check the last-modified time every time a file is accessed. Consequently, by default, IIS 6.0 checks the last-modified time at most every five seconds; otherwise, it assumes the file has not changed. There is a five-second window where IIS will deliver a stale file out of the cache.
For some sites, a five-second window will be too large a window, and for others, too small. The sampling interval is configurable with the following registry keys, which are not present by default:
Static pages Set the registry property, FileAttributeCheckThreshold, a DWORD value, located at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Inetinfo\Parameters. Also, note that the server-side includes file handler (Ssinc.dll) makes use of the user-mode static-file cache, so the configuration you apply to the user-mode static-file cache also applies to .stm, .shtml, and any other files you have mapped to Ssinc.dll. If the DoDirMonitoringForUnc registry property, a DWORD value located at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Inetinfo\Parameters, is set to False, IIS checks the cache entries for change after a period of time equal to the value set for the FileAttributeCheckThreshold registry property. Effective with Windows Server 2003 SP1, IIS checks both the worker process file cache entries and the HTTP.sys cache entries.
ASP Scripts Set the registry property, FileMonitoringTimeoutSeconds, a DWORD value, located at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\ASP\Parameters.
Using the last-modified cache update mechanism will result in more reliable and secure delivery of content. Additionally, it will scale well on a wide application structure (where your Web server has lots of applications pointing at thousands of different directories). There is, however, a performance penalty that may be noticeable in regards to static content.
File Change Notification
In most cases, performance of UNC-based content will be slightly slower in the default caching configuration (as compared with using change notification–based caching). If you do observe a difference, it will likely be with static files rather than ASP files. With ASP requests, the performance penalty between checking the last-modified time and listening to change notifications is quite small, because no matter which method is used for cache updates, the biggest portion of any latency is in the re-compilation and execution of the ASP page.
IIS monitors for change notification events at the root level of every virtual directory. Large numbers of virtual directories can cause significant overhead, but if you use a file server that reliably reports change notifications and you have a small number of sites or virtual directories using remote content, using change notification is faster. For example, if you have a single Web site using a couple of applications with all your content stored on a Windows Server 2003 file server, it is recommended that you use the change notification method of caching.
Change notification-based caching works best when:
The number of sites or virtual directories using UNC content is low.
Files are small enough to be cached (under 256K).
Requests are concentrated among a few files, that is, the cache hit rate is high.
The performance of benefits provided by the kernel-mode cache is important.
You can enable change notification-based caching by adding the following registry keys, which are not present by default:
Static Pages Set the registry property, DoDirMonitoringForUNC, a DWORD value located at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Inetinfo\Parameters, to True. Also, note that the server-side includes file handler (Ssinc.dll) makes use of the user-mode static-file cache, so the configuration you apply to the user-mode static-file cache also applies to .stm, .shtml, and any other files you’ve mapped to Ssinc.dll. Effective with Windows Server 2003 SP1, IIS checks both the worker process file cache entries and the HTTP.sys cache entries.
ASP Scripts Set the registry property, EnableChangeNotificationForUNC, a DWORD value, located at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\ASP\Parameters.