Using HTTP Compression

To more efficiently use available bandwidth, enable IIS HTTP compression. HTTP compression provides faster transmission time between compression-enabled browsers and IIS, regardless of whether your content is served from local storage or a UNC resource. You can compress static files and application response files. Compressing application response files is usually called dynamic compression.

 

This section includes the following information:

Enabling HTTP Compression [http://technet2.microsoft.com/WindowsServer/en/Library/ae342c42-fbc4-4ab7-b9ac-20a89f0fa4ad1033.mspx] : Describes how to enable compression.

Customizing the File Types IIS Compresses [http://technet2.microsoft.com/WindowsServer/en/Library/9fbab3d5-6f02-4c2c-a018-21e1f69d986e1033.mspx] : Describes how to add or remove file types from IIS compression.

Related Information

For a detailed discussion of how HTTP compression works, how to test compression, and detailed compression configuration options, see Using HTTP Compression for Faster Downloads [http://technet2.microsoft.com/WindowsServer/en/Library/14A97D47-93FE-4AEA-928E-9F24ED56A9831033.mspx] .

For more information about improving the performance of IIS network resources using related features like bandwidth throttling and connection time-outs, see Administering Network Resources [http://technet2.microsoft.com/WindowsServer/en/Library/F51B2479-ED9B-4AE0-AC8B-A3490DE546931033.mspx] .

 

 

 

-----


Enabling HTTP Compression

You can enable HTTP compression server-wide or on a specific directory. HTTP compression improves bandwidth utilization and speeds up Web site performance. In addition, you can compress static or dynamic responses.

 Important:

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. 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".

Introduction to and procedures for enabling HTTP compression using IIS Manager and command-line scripts.

Procedures

To enable global HTTP compression by using IIS Manager

1.

In IIS Manager , double-click the local computer, right-click the Web Sites folder, and then click Properties.

2.

Click theService tab, and in the HTTP compression section, select the Compress application files check box to enable compression for dynamic files.

3.

Select the Compress static files check box to enable compression for static files.

4.

In the Temporary directory box, type the path to a local directory or click Browse to locate a directory. once a static file is compressed, it is cached in this temporary directory until it expires, or the content changes. The directory must be on the local drive of an NTFS–formatted partition. The directory cannot be compressed or shared, and the access control lists (ACLs) for the directory must include Full Control access to the identity of the application pool or to the IIS_WPG group.

5.

Under Maximum temporary directory size, click a folder size option. If you specify a maximum size under Limited to (in megabytes) (the default setting is 95 MB), then when the limit is reached, IIS automatically cleans up the temporary directory by applying the "least recently used" rule.

6.

Click Apply, and then click OK.

 Important:

You must be a member of the Administrators group on the local computer to run scripts and executables. 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:MyComputer\Administratorcmd to open a command window with administrator rights and then type cscript.exeScriptName (include the script's full path and any parameters).

To enable global HTTP compression by using Adsutil.vbs

1.

Open a command prompt.

2.

To enable dynamic compression, type the following at the command prompt and then press ENTER:

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true

3.

To enable static compression, type the following at the command prompt and then press ENTER:

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true

 

To enable HTTP Compression for Individual Sites and Site Elements

To disable static compression for only a single directory, first enable global static compression (if it is disabled) and then disable static compression at that directory. For example, to enable static compression for a directory at http://www.contoso.com/Home/StyleSheets, perform the following steps:

1.

Disable global static compression by executing the following command at a command prompt:

adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression true

2.

Enable static compression at this directory by executing the following command at a command prompt:

adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression false

1.

Disable global static compression by executing the following command at a command prompt:

adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression false

2.

Enable static compression at this directory by executing the following command at a command prompt:

adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression true

 

 

 

-----


Customizing the File Types IIS Compresses

You can customize the file types IIS compresses. Enabling static file compression compresses .htm, .html, and .txt files. Enabling dynamic compression compresses .asp, .dll, and .exe files.

 Important:

You must be a member of the Administrators group on the local computer to run scripts and executables. 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:MyComputer\Administrator cmd to open a command window with administrator rights and then type cscript.exe ScriptName (include the script's full path and any parameters).

Procedures

To add one or more file types to the server-wide static compression configuration

1.

From the Start menu, click Run.

2.

In the Open box, type cmd, and click OK.

3.

Type both of the following commands:

cscript adsutil.vbs SET W3SVC/Filters/Compression/Deflate/HcFileExtensions "htm" "html" "txt" "newext" wherenewext is a file type you want to compress (for example, Microsoft Word or Excel documents), then press ENTER. You can add multiple file types separated by spaces.

cscript adsutil.vbs SET W3SVC/Filters/Compression/gzip/HcFileExtensions "htm" "html" "txt" "newext" where newextis a file type you want to compress, then press ENTER. You can add multiple file types separated by spaces.

 Note:

To remove one or more file types from the server-wide static compression configuration, repeat the previous two commands, leaving out the file type you want to remove.

To add one or more file types to the server-wide dynamic compression configuration

1.

From the Start menu, click Run.

2.

In the Open box, type cmd, and click OK.

3.

Type both of the following commands:

cscript adsutil.vbs SET W3SVC/Filters/Compression/Deflate/HcScriptFileExtensions "asp" "dll" "exe" "newext"where newext is a file type you want to compress (for example, aspx, a commonly used ASP extension), then press ENTER. You can add multiple file types separated by spaces.

cscript adsutil.vbs SET W3SVC/Filters/Compression/gzip/HcScriptFileExtensions "asp" "dll" "exe" "newext" where newext is a file type you want to compress, then press ENTER. You can add multiple file types separated by spaces.

 Note:

To remove one or more file types from the server-wide dynamic compression configuration, repeat the previous two commands, leaving out the file type you want to remove.

 

 

 

-----

 

Using HTTP Compression for Faster Downloads

If your Web sites use large amounts of bandwidth or if you want to use bandwidth more effectively, consider enabling HTTP compression, which provides faster transmission times between IIS and compression-enabled browsers regardless of whether your content is served from local storage or a UNC resource. If your network bandwidth is restricted, HTTP compression can be beneficial unless your processor usage is already very high.

IIS provides the following compression options:

Static files only.

Dynamic application responses only.

Both static files and dynamic application responses.

Dynamic processing can affect CPU resources because IIS does not cache compressed versions of dynamic output. If compression is enabled for dynamic responses and IIS receives a request for a file that contains dynamic content, the response that IIS sends is compressed every time it is requested. Because dynamic compression consumes considerable CPU time and memory resources, use it only on servers that have slow network connections but CPU time to spare.

Compressed static responses can be cached and therefore do not affect CPU resources like dynamic responses do.

How HTTP Compression Works

When IIS receives a request, it checks whether the browser that sent the request is compression-enabled. (Recent versions of Microsoft� Internet Explorer and most other browsers typically send the following header if they are compression-enabled: Accept-Encoding: gzip, deflate.) IIS then determines whether the request is for a static file or for dynamic content.

If the content of the file is static, IIS checks whether the file has previously been requested and is already stored in a compressed format in the temporary compression directory. If a compressed version of the requested file is not found, IIS sends an uncompressed version of the requested file to the client browser while a background thread compresses the requested file. The newly compressed file is then stored in the compression directory, and subsequent requests for that file are serviced directly from the compression directory. In other words, an uncompressed version of the file is returned to the client unless a compressed version of the file already exists in the compression directory.

If the file contains dynamic content, IIS compresses the response as it is generated and sends the compressed response to the browser. No copy of the file is cached by the Web server.

The performance cost of compressing a static file is modest and is typically incurred only once, because the file is then stored in the temporary compression directory. The cost of compressing dynamically generated files is somewhat higher because the files are not cached and must be regenerated with each request. The cost of expanding the file at the browser is minimal. Compressed files download faster, which makes them particularly beneficial to the performance of any browser that uses a network connection with restricted bandwidth (a modem connection, for example).

When you enable HTTP compression, compressed files are given a default expiration date of Jan. 1, 1997. This expiration date prevents proxy servers from serving cached copies of compressed files to browsers that are not compression-enabled. This expiration date also forces browsers to return to the server for a fresh copy of the file when the user makes a new request instead of displaying a cached copy of the file. When you enable HTTP compression, the default settings for the HcExpiresHeader, HcCacheControlHeader, and HcSendCacheHeaders metabase properties ensure that older clients and proxy servers do not attempt to cache compressed files. Before you change these settings, see Metabase Property Reference for information about these and related metabase properties.

Determining Whether HTTP Compression Will Improve Performance

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 evaluate how much of your processor is typically being used, follow these steps:

1.

Establish a baseline for your processor usage by using System Monitor to log the following counters over several days. If you use Performance Logs and Alerts, you can log the data to a database and then query the data, examining the results in detail.

Processor\% Processor Time. 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 need to watch the individual processors as well as the total to discover any imbalance in the workload.

Network Interface\Bytes Sent/sec. Counters for the Network Interface performance object display the rate at which bytes are transmitted over a TCP/IP connection by monitoring the counters on the network adapter. For information about additional counters to monitor for this object, see Table 6.8.

2.

Enable compression, and continue to log the values for these counters for an extended period — preferably for several days — so you have a good basis for comparison.

Collect a broad sample to determine how compression affects various aspects of performance. Conduct the following tests:

Enable static compression only, dynamic compressions only, and both.

Change the list of files that you use for compression testing for both static and dynamic content.

Vary the compression level. Try this on all content types.

3.

Compare the data from monitoring with and without compression, and with different types of compression, different compression levels, and different files.

 Important:

If you see signs of blocking or bottlenecking during the preceding testing, 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.

Choosing Compression Options

When you configure HTTP compression by using IIS Manager, IIS 6.0 automatically applies the default settings shown in Table 6.12. You can configure custom settings for each compression option by editing the metabase or alternatively — in the case of the compression directory — by using IIS Manager.

 

Table 6.12 Default Settings When HTTP Compression Is Enabled

Compression OptionsFile TypeDefault ConfigurationConfiguration Method

File types compressed

Static

.txt, .htm, and .html

Metabase

 

Dynamic

.exe, .dll, and .asp

Metabase

Compression schemes

Static

Both gzip and deflate

Metabase

 

Dynamic

Both gzip and deflate

Metabase

Compression level

Static

10

Metabase

 

Dynamic

0

Metabase

Compression directory

Static

Size: 95 MB

Location1: %Windir%\IIS Temporary Compressed Files

Metabase or IIS Manager

 

Dynamic

No directory2

N.A.

1 The compression directory must reside on an NTFS file system volume.

2 When dynamic files are compressed, they are not cached.

If the default HTTP compression configuration does not meet the needs of your organization, you can make the following changes to the configuration:

Specify additional file types to compress. Edit the HcFileExtensions metabase property (for static files) and the HcScriptFileExtensions metabase property (for dynamic files) to apply compression to additional file types. Add only compressible files types to your compression scheme because trying to compress an already compressed file — such as .jpg, .mp3, or .zip files — wastes processing time.

Enable or disable the gzip or deflate compression scheme. When you use IIS Manager to enable compression, IIS enables both compression schemes (gzip and deflate), so that IIS can apply whichever compression scheme the client requests. You can edit the metabase to specify that only a particular compression scheme is used. If you disable the only compression scheme that a client supports, the server replies with an uncompressed file.

 Note:

Disabling either the gzip or deflate compression schemes can have unintended consequences, such as not compressing responses to a particular browser. For maximum compatibility, it is recommended that you leave both compression schemes enabled.

Change the level of compression for static or dynamic files. Compression levels range from 0 through 10. Higher compression levels produce smaller compressed files but use more CPU and memory. Lower compression levels produce slightly larger compressed files, but with less impact on CPU and memory usage. To configure a compression level other than 10 for static files and other than zero for dynamic files, edit the HcOnDemandCompLevel and HcDynamicCompressionLevel metabase properties.

For dynamic compression, increasing the compression level can significantly increase CPU usage. The default compression level of zero uses the least amount of CPU resources and can increase performance if network bandwidth is adequate. Raise the dynamic compression level above zero only if you need more network bandwidth and have sufficient CPU capacity to handle the extra load.

Change the location or size of the compression directory. To change the location and size of the compression directory for static files, edit the HcCompressionDirectory, HcDoDiskSpaceLimiting, and HcMaxDiskSpaceUsage metabase properties.

Compression Strategies

When the CPU of your server is not heavily loaded, the simplest compression strategy is to enable static and dynamic compression for all of the sites and site elements (directories and files) on the server. This is known as global HTTP compression. However, when the CPU load of your server is high, you might not want to enable compression for all of the sites and site elements on the server.

Depending on CPU usage, there are two strategies for fine tuning which sites and site elements are compressed:

Enable compression globally, and then disable compression selectively for specific sites or site elements.

Leave global compression disabled, and then enable compression selectively for specific sites or site elements.

Enabling Global HTTP Compression

When you enable HTTP compression by using IIS Manager, IIS applies compression according to the default settings shown in Table 6.12. With the exception of the location and size of the compression directory, you cannot change the default settings by using IIS Manager. Instead, you must edit the metabase to change the default settings.

 Important:

After enabling HTTP compression (either by using IIS Manager or by editing the metabase), you must restart IIS for the change to take effect.

For more information about enabling global HTTP compression by using IIS Manager and through Adsutil.vbs, see Enabling HTTP Compression .

Configuring HTTP Compression for Individual Sites and Site Elements

All of the compression configurations discussed so far are located under W3SVC/Filters/Compression in the metabase and are used to apply global HTTP compression, which is applied by using IIS Manager or by using one of the metabase properties that are used for global compression (beginning with Hc). IIS 6.0 offers two new metabase properties, DoStaticCompression and DoDynamicCompression(beginning with Do), which can be used to enable or disable compression at the individual site and site element levels. Use these two new properties to apply compression to individual namespaces. Hence, you can enable global compression by using IIS Manager or the Hc global properties and then disable one of the Do properties (or vice versa) to obtain compression at a specific location in the IIS metabase.

For more information about enabling compression for individual Sites and Site elements, see Enabling HTTP Compression .

Specifying File Types and Compression Schemes by Editing the Metabase

After enabling HTTP compression, you can use the Adsutil.vbs command-line utility (located in the systemroot\Inetpub\AdminScripts folder) to edit the metabase, specifying which static or dynamic file types to compress and which compression scheme to apply.

Using Adsutil.vbs, you can customize HTTP compression in the following ways:

Apply the gzip or deflate compression scheme, or both. To apply both schemes, you must execute a separate set command for each compression scheme.

Customize the file types to which both static and dynamic compression are applied. You must execute a separate set command for each compression type. If you use IIS Manager to enable compression and you then use Adsutil.vbs to specify specific static or dynamic file types, you replace any default values that were applied by IIS Manager.

 Note:

For compression to be performed, the HcDoStaticCompression metabase property must be set to true (for static compression) and the HcDoDynamicCompression metabase property must be set to true (for dynamic compression). You can set these by using IIS Manager or Adsutil.vbs. For instructions, see the procedures in the preceding section.

The following syntax enables compression at the W3SVC level (which means it is applied to all Web sites and virtual directories on the Web server):

cscript.exe adsutil.vbs set W3svc/Filters/Compression/{GZIP|DEFLATE}/
{HcFileExtensions "StaticFileType" ...}|{HcScriptFileExtensions "DynamicFileType" ...}

You must restart the WWW service before any changes take effect. For information about restarting a service, see Common IIS 6.0 Administrative Tasks . Table 6.13describes the parameters for customizing file types and compression schemes.

 

Table 6.13 Parameters for Setting Compression Schemes and File Types for HTTP Compression

ParameterDescription
GZIP|DEFLATE
              
            

Specifies which compression scheme (either gzip or deflate) to apply to the specified file types. To enable both compression schemes, you must run this command once for each compression scheme. For maximum compatibility, leave both compression schemes enabled.

HcFileExtensions
"" ... 

Specifies which static file types to apply the compression scheme to — for example, .txt, .js, .css, .doc, or .xls files. To specify a file type, enclose the file name extension (without the leading period) in quotation marks. Separate multiple file types with a space. This parameter cannot be executed together with the HcScriptFileExtensions "DynamicFileType" parameter.

HcScriptFileExtensions
" ...

Specifies which dynamic file types to apply the compression scheme to — for example, .exe, .dll, or .asp files. To specify a file type, enclose the file name extension (without the leading period) in quotation marks. Separate multiple file types with a space. This parameter cannot be executed together with theHcFileExtensions "StaticFileType" parameter.

Important   Setting the HcScriptFileExtensions parameter to an empty string can adversely affect your servers performance. If this parameter is empty, all dynamic responses are sent compressed. In addition, any static file type not specified in HcFileExtensions is dynamically compressed and therefore not cached.

For example, the following command uses a deflate compression scheme to apply static compression at the W3SVC level to text files (.txt) and cascading style sheets (.css):

cscript.exe adsutil.vbs set w3svc/Filters/Compression/DEFLATE/HcFileExtensions "txt" "css"

Specifying the Location and Size of the Compression Directory for Static Compression

Three metabase properties enable you to change the location of the default directory for static compression and to limit its size.

Changing the location of the compression directory

The HcCompressionDirectory metabase property specifies the folder where compressed versions of static files are temporarily cached. By default, the compression directory is at %Windir%\IIS Temporary Compressed Files.

Due to a number of differences between NTFS and FAT volumes — such as differences in time stamping and access control mechanisms, and the efficiency with which NTFS handles directories that contain large numbers of files — the compression directory must reside on an uncompressed and unshared NTFS volume. In addition, the access control lists (ACLs) for the folder must include Full Control access to the identity of the application pool or to the IIS_WPG group. If a requested file resides on an NTFS volume and the compression directory is on a FAT volume, IIS does not perform HTTP compression on that file.

Setting a size limit for the compression directory

In addition, you can configure the HcDoDiskSpaceLimiting and HcMaxDiskSpaceUsage metabase properties to limit the amount of disk space that all files in the compression directory can occupy. HcDoDiskSpaceLimiting enables disk space limiting. If it is set to true, IIS limits compressed files to no more than the number of bytes specified by HcMaxDiskSpaceUsage. After the limit is reached, compressed files are removed from the compression directory on a least recently used basis. If HcDoDiskSpaceLimiting is set to false, no disk space limit is enforced for the compression directory.

HcDoDiskSpaceLimiting is relevant only if you have set the property HcDoOnDemandCompression to true. For more information about these metabase properties, see Metabase Property Reference .

 Important:

Limiting the use of disk space has a significant impact on performance because additional overhead is required to check for the limit. Use this feature only when you lack adequate disk space to cache all content files on your Web server.

Disabling HTTP Compression for Requests That Come Through Certain Proxy Servers

Certain HTTP proxy servers, including some advertised as HTTP 1.1–compliant, do not handle the caching of compressed objects correctly. The HcNoCompressionForProxies metabase property allows you to disable the HTTP 1.1 response for compression requests that come through proxy servers.

In addition, you can use the HcNoCompressionForHttp10 metabase property to disable compression for requests that contain an HTTP 1.0 version number. HTTP 1.0, as described in RFC 1945, Hypertext Transfer Protocol — HTTP/1.0, provides a minimal level of support for certain types of compression. However, some confusion exists concerning HTTP 1.0 compression, especially with regard to proxy servers. To minimize the chance of inappropriately returning a compressed file to a client that cannot decompress it, you can use the HcNoCompressionForHttp10 metabase property to disable compression in questionable scenarios.

For more information about the many metabase properties that you can set when configuring HTTP 1.1 compression, including a complete list of all the properties you can set, see IIsCompressionSchemes (ADSI) in the IIS 6.0 SDK .




Posted by 떼르미
,


자바스크립트를 허용해주세요!
Please Enable JavaScript![ Enable JavaScript ]