How can I get gzip compression in IIS7 working? How can I get gzip compression in IIS7 working? asp.net asp.net

How can I get gzip compression in IIS7 working?


There was a thread on forums.iis.net about this during the iis 7 beta. Turned out the guy didn't have the modules installed, but it sounds like you've ruled that out from your opening sentence.

Microsofts key advice for him was to enable failed request tracing to find out what was going wrong. This is possibly one of the most under-appreciated features of IIS7, but certainly one of the most powerful.

  • Open IIS Manager.
  • Go to your site, and on the actions pane (the very far right), click 'Failed Request Tracing...' under the 'Configure' section.
  • Click 'enable'.
  • Then, in the features view, click 'Failed request tracing rules'. Click add, next, enter 200 for the status code, next, click finish.

If you don't see "Failed Request Tracing" in the actions pane, you'll need to add the feature to the server - either using the "Add Role Services" wizard (Health and Diagnostics\Tracing) or through the Web Platform Installer (Products\Server\IIS: Tracing), and then close and re-open IIS Manager.

Next, rerun your test. This will generate some log info for us to examine.

Look in c:\inetpub\logs\FailedReqLogFiles\w3svcx. You will see a bunch of files named fr000xx.xml. Open up any one of them in your browser. (By the way, if you copy these files anywhere, make sure freb.xsl is there. Also, don't delete freb.xsl - if you do, just delete the whole directory or copy it from another location, as IIS only creates it once per folder.)

Click the 'request details' tab and select 'complete request trace'. Search the page for 'compress' - you should find it in several areas; once for static content, and once for dynamic content.

If you don't find either of them, IIS isn't configured correctly. If you do find them, you should see them followed by a compression_success and a compression_do. Success is self explanatory; the 'do' indicates what it did - in my case, it showed "OriginalSize 1462784 CompressedSize 179482"

Since yours isn't working, hopefully you will see something different that helps you solve the problem.

Make sure you turn this off when you're done by disabling failed request tracing in the actions pane for your website.


We had a similar problem and it turns out that IIS7 does some dynamic CPU based throttling here..

http://www.iis.net/ConfigReference/system.webServer/httpCompression

dynamicCompressionDisableCpuUsage

Optional uint attribute.

Specifies the percentage of CPU utilization at which dynamic compression will be disabled.

Note: This attribute acts as an upper CPU limit at which dynamic compression is turned off. When CPU utilization falls below the value specified in the dynamicCompressionEnableCpuUsage attribute, dynamic compression will be reenabled.

The default value is 90.


dynamicCompressionEnableCpuUsage

Optional uint attribute.

Specifies the percentage of CPU utilization below which dynamic compression will be enabled. The value must be between 0 and 100. Average CPU utilization is calculated every 30 seconds.

Note: This attribute acts as a lower CPU limit below which dynamic compression is turned on. When CPU utilization rises above the value specified in the dynamicCompressionDisableCpuUsage attribute, dynamic compression will be disabled.

The default value is 50.

Note the defaults -- if your IIS7 hits 90% CPU usage, it will disable all dynamic gzipped content until CPU usage dips back below 50%!

Also, some great recommendations and benchmarks here on the real CPU cost of GZIP.

http://weblogs.asp.net/owscott/archive/2009/02/22/iis-7-compression-good-bad-how-much.aspx

Long story short, unless you regularly have dynamic pages well in excess of 200kb, it's a non-issue.


Following the excellent advice of JohnW, I too enabled logging to find the culprit, though the reason for the failure turned out to be different:

STATIC_COMPRESSION_NOT_SUCCESS Reason 14 Reason NOT_FREQUENTLY_HIT

In short, it appears that if you don't hit the page frequently enough then IIS7 will not deem it worthy of compressing, which seems a little bit odd to me. Nonetheless, makes sense in this case because I was just trying to test it on a local machine.

According to this page, the default appears to be that a page has to be hit 2 times within 10 seconds to be a "frequent hit". If you really want to, you can override the default in applicationHost.config (%systemroot%\Windows\System32\inetsrv\config). At least for me it's a locked attribute, so you won't be able to override it in your own web.config.

<serverRuntime frequentHitThreshold="1" />

Also, I note now that SO already had this answer here: In IIS7, gzipped files do not stay that way.