Monday, January 11, 2010

Everything you ever wanted to know about compression but were afraid to ask…

Using HTTP Compression for Faster Downloads (IIS 6.0)



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.





Top of page
Top of page




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.





http://img.microsoft.com/technet/images/important.gif
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.





Top of page
Top of page




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 Options




File Type




Default Configuration




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




http://img.microsoft.com/technet/images/note.gif
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.






Top of page
Top of page




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.






Top of page
Top of page




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.




http://img.microsoft.com/technet/images/important.gif
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
.





Top of page
Top of page




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
.





Top of page
Top of page




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.





http://img.microsoft.com/technet/images/note.gif
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 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




Parameter




Description





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.





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.





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"





Top of page
Top of page




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
.




http://img.microsoft.com/technet/images/important.gif
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.





Top of page
Top of page




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
.






Enabling HTTP Compression (IIS 6.0)



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.




http://img.microsoft.com/technet/images/important.gif
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"
.




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.





http://img.microsoft.com/technet/images/important.gif
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














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




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






An example script
is on 192.168.69.198 C:\Inetpub\AdminScripts\CompressionScript.bat



Note! To compress an individual site
you need to know its number. Use
adsutil



Using the Adsutil.vbs Administration Script



Updated: August 22, 2005



Adsutil.vbs is an IIS
administration utility that uses Microsoft Visual Basic Scripting Edition
(VBScript) with Active Directory Service Interfaces (ADSI) to manipulate the IIS
configuration. This script should be run using CScript, which is installed with
Windows Script Host.













Important
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 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. From the command prompt, type runas
/profile /
user:mymachine\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).





Usage



Cscript.exe adsutil.vbs COMMAND
<path> [<param>...]



Cscript.exe adsutil.vbs COMMAND
[<path> [<parameters>...]]

















































































Command





Description




GET Path




Display chosen parameter.




SET Path Value




Assign a new value.




ENUM Path "/P"




Enumerate all parameters for the path. /P
Enumerate the paths only (no data).




ENUM_ALL "/P"




Enumerate all parameters. /P Enumerate the
paths only (no data).




DELETE Path




Delete the path or parameter.




CREATE Path [KeyType]




Create the path and assign it the KeyType.




APPCREATEINPROC Path




Create an in process application.




APPCREATEOUTPROC Path




Create an out-of-process application.




APPDELETE Path




Delete the application (if present).




APPUNLOAD Path




Unload an out-of-process application.




APPGETSTATUS Path




Get status of the application.




FIND Path




Find the paths where a parameter is set.




START_SERVER Path




Start the Web site.




STOP_SERVER Path




Stop the Web site.




PAUSE_SERVER Path




Pause the Web site.




CONTINUE_SERVER Path




Unpause the Web site.




HELP




Print all available commands.





Notes




  • <Path> is the path of the node for which you are setting
    the property, combined with the name of the property that you are setting. For
    example, if you want to set the ServerComment for Web server number 1,
    the command would be as follows:


    adsutil
    SET w3svc/1/ServerComment "Web Server Number 1"


    The next time


    IIS Manager
    is opened, it will reflect the name of the Web server as
    "Web Server Number 1."


  • The switch "-s:server name" can be used after any
    command to execute the command on a remote computer. (See first example below.)




Examples




  • Cscript.exe adsutil.vbs GET W3SVC/1/ServerBindings
    -s:remotecomputer1


  • Cscript.exe adsutil.vbs SET W3SVC/1/ServerBindings ":81:"


  • Cscript.exe adsutil.vbs CREATE W3SVC/1/Root/MyVdir
    "IIsWebVirtualDir"


  • Cscript.exe adsutil.vbs START_SERVER W3SVC/1


  • Cscript.exe adsutil.vbs ENUM /P W3SVC





No comments:

Post a Comment