How to check HTTP Compression with HttpWatch

calendarJuly 10, 2009 in Automation , C# , HttpWatch , Optimization

HTTP compression is one of the easiest and most effective ways to improve the performance of a web site. A browser indicates that it supports compression with the Accept-Encoding request header and the server
indicates the compression type in the Content-Encoding response header.

This screenshot from the Stream tab of HttpWatch shows these headers and the compressed content being returned from the server:

Compressed Page

Here’s another screenshot of a page that is not compressed:

Page with no compression

The browser still indicated that it accepted gzip and deflate compression, but the server ignored this and returned uncompressed HTML with no Content-Encoding header.

The easiest way to check the amount of compression achieved is to use the Content tab in HttpWatch to view a ‘200 OK’ response from the server:

Compressed Content

Don’t try checking for compression on other HTTP status codes. For example, a ‘304 Not Modified’ response will never have any compression saving because no content is returned across the network from the web server. The browser just loads the content fom the cache as shown below:

Content Tab with 304

So, if you want to see if compression is enabled on a page, you’ll either need to force a refresh or clear the browser cache to make sure that the content is returned from the server. The HttpWatch Automation API lets you automate these steps. Here’s an example using C# that reports how many bytes were saved by compressing a page’s HTML:

// Set a reference to the HttpWatch COM library
// to start using the HttpWatch namespace
//
// This code requires HttpWatch version 6.x
//
 
using HttpWatch;
 
namespace CompressionCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://www.httpwatch.com";
            Controller controller = new Controller();
 
            // Create an instance of IE (For Firefox use
            // controller.Firefox.New("") )
            Plugin plugin = controller.IE.New();
 
            // Clear out all existing cache entries
            plugin.ClearCache();
 
            plugin.Record();
            plugin.GotoURL(url);
 
            // Wait for the page to download
            controller.Wait(plugin, -1);
 
            plugin.Stop();
 
            // Find the first HTTP/HTTPS request for the page's HTML
            Entry firstRequest = plugin.Log.Pages[0].Entries[0];
 
            int bytesSaved = 0;
            if (firstRequest.Content.IsCompressed)
            {
                bytesSaved = firstRequest.Content.Size
                                   - firstRequest.Content.CompressedSize;
            }
 
            System.Console.WriteLine("Compression of '" +
                firstRequest.URL + "' saved " + bytesSaved + " bytes");
 
            plugin.CloseBrowser();
        }
    }
}

Tip: If you access a web site through a proxy you may not see the effect of compression. This is because some proxies strip out the Accept-Encoding header so that they don’t have to process compressed content. Tony Gentilcore’s excellent ‘Beyond Gzipping’ talk at Velocity 2009 described how 15% of visitors to your site will not receive compression due to problems like this. A simple way to effectively bypass proxy filtering for testing purposes is to use HTTPS if it is available. For example, try https://www.httpwatch.com if you don’t see compression on http://www.httpwatch.com.

Using Firefox, HttpWatch and Internet Explorer on Vista 64-bit

calendarMay 9, 2009 in Automation , C# , Firefox , HttpWatch , Internet Explorer , Javascript

The 64-bit version of Windows Vista is becoming increasing popular due to its ability to access more than 4 GB of physical memory. To an ordinary Windows user, there are few noticeable differences from the 32-bit version because it can run both 32-bit and 64-bit programs.

In this post we wanted to answer some of the questions you may have about Windows Vista 64-bit and the effect it has on the use of Firefox, HttpWatch and Internet Explorer (IE).

How can I tell if a program is running in 32-bit or 64-bit mode?

The Task Manager on Vista 64-bit shows 32-bit tasks with a ‘*32′ after the process name. If there’s no ‘*32′ after the name then it is running in 64-bit mode. This screen shot shows a 32-bit process called page_check running on Vista 64-bit:

32-bit Program Running on Vista 64-bit

Why does IE run in 32-bit mode by default on Vista 64-bit?

Clicking on the launch bar IE icon in Vista 64-bit starts the 32-bit version of IE:

32-bit version of IE on Vista 64-bit

A 64-bit version of IE is available but you have to explicitly select it from the Start menu:

64-bit version of IE

Microsoft has done this because the 64-bit version of IE can only load 64-bit browser extensions and most  extensions, such as the Adobe Flash player, are only available in 32-bit.

Here’s what Adobe says about 64-bit support:

Adobe Flash Player is not supported for playback in a 64-bit browser. However, you can run Flash Player in a 32-bit browser running on a 64-bit operating system.


Adobe is working on Flash Player support for 64-bit platforms as part of our ongoing commitment to the cross-platform compatibility of Flash Player. We expect to provide native support for 64-bit platforms in an upcoming release of Flash Player following Flash Player 10.

Without the Flash player, you can’t use sites like YouTube or BBC iPlayer. That’s a non-starter for many web users and the reason why 32-bit IE is the default on Vista 64-bit.

Microsoft is also putting off 64-bit support in Silverlight until other 64-bit extensions are available:

Right now our plan is to run SL in 32-bit mode (and not have a 64-bit native version). This is mostly because other browser plug-ins (and most browsers) don’t support 64-bit yet. We are looking at adding native 64-bit support in the future though.

Can I run Firefox in 64-bit mode on Vista 64?

There’s currently no official build of Firefox for 64-bit Windows as stated in a Mozilla support forum:

There are no releases or nightly builds of 64 bit Firefox for Windows from Mozilla as the earliest release to likely have 64-bit versions is Firefox 4.0. The only option you have is either roll your own or use a third-party build.

There’s little motivation for the browser vendors to go 64-bit because unlike other applications, such as memory hungry video editors or database servers, web browsers will not see significant performance benefits in 64-bit mode and there is also the problem with the lack of 64-bit extensions.

Can I use HttpWatch on Vista 64-bit?

Yes, you can use HttpWatch on Vista 64-bit but it is currently only available in 32-bit. This means that the HttpWatch plug-in can only be used in the 32-bit edition of IE. We will provide 64-bit plug-ins when Adobe, Microsoft and Mozilla provide significant 64-bit support.

The automation interface can be used from 64-bit programs without making any changes so as long as you have HttpWatch version 6.1.32 or later.

In some cases, such as accessing a .hwl file opened with the OpenLog method, you may see reduced performance in a 64-bit program. This is because the 64-bit API support in HttpWatch uses a separate WIN32 process rather than directly loading the API. To avoid this issue make sure that your client program runs 32-bit (see below).

Can I use the HttpWatch version 5.x automation on Vista 64-bit?

This will work, but you will need to ensure that your program runs in 32-bit mode. Otherwise, you will see this error when you attempt to create an instance of the HttpWatch controller object:

Unhandled Exception: System.Runtime.InteropServices.COMException (0x80040154): Retrieving
the COM class factory for component with CLSID {C4CEDB78-2B64-4703-99BE-A037A849D703}
failed due to the following error: 80040154.

If you’re seeing this error with HttpWatch version 6 make sure that you’ve installed version 6.1.32 or later.

How can I get my HttpWatch automation program to run 32-bit?

As mentioned above, you will need to ensure that a program using the HttpWatch automation API runs in 32-bit mode if:

  • You are using HttpWatch version 5.x
  • You want to improve data access performance on log files that are opened using the OpenLog method.

.Net projects (e.g. C# or VB.Net) have a default configuration setting of ‘Any CPU’. This causes them to automatically run as a  64-bit process on Vista 64-bit. To force them to always run 32-bit you’ll need to change this setting to ‘x86′ in Visual Studio:

x86build

Script based programs, such as Javascript or VBScript, that use the Windows Scripting Host will normally run in 64-bit on Vista 64-bit because cscript.exe and wscript.exe are  64-bit programs. You can force the use of 32-bit by using the script programs that are installed in the Windows\SysWow64 directory:

32bitwsh

The sample automation code that is installed with HttpWatch version 6.1.32 or later, uses the ‘x86’ setting  in C# projects and includes instructions on how to run the Javascript samples in 32-bit mode.

Using HttpWatch with WatiN

calendarOctober 30, 2008 in Automation , C# , HttpWatch , Internet Explorer

WatiN (pronounced as What-in) is a browser automation library for .NET that was inspired by the Ruby based Watir and FireWatir frameworks. It allows C# and VB.Net applications to programatically interact with a browser to perform tasks such as going to a web page, filling out fields and clicking on buttons. The current version only works with IE, but version 2.0 will include support for Firefox.

We have previously discussed the use of Ruby, Watir and HttpWatch and version 6.0 now contains Watir sample code that works with both IE and Firefox. HttpWatch can also be used alongside WatiN to record HTTP traffic and performance statistics while running an automated script. We adapted the Getting Started WatiN sample to use HttpWatch to record the Google results page. The modified code is shown below:

// This code works with WatiN version 1.3
using System;
using WatiN.Core;
 
namespace WatiNTest
{
  class WatiNTestWithHttpWatch
  {
    [STAThread]
    static void Main(string[] args)
    {
        // Open a new Internet Explorer window and
        // goto the google website.
        IE ie = new IE("http://www.google.com");
 
        // Attach HttpWatch to this new instance of IE
        HttpWatch.Controller ct = new HttpWatch.Controller();
        HttpWatch.Plugin plugin = ct.IE.Attach((SHDocVw.IWebBrowser2)ie.InternetExplorer);
 
        // Start recording a log file in HttpWatch
        plugin.Record();
 
        // Find the search text field and type Watin in it.
        ie.TextField(Find.ByName("q")).TypeText("WatiN");
 
        // Click the Google search button.
        ie.Button(Find.ByValue("Google Search")).Click();
        ie.WaitForComplete();
 
        // Stop recording and save an HttpWatch log file
        plugin.Stop();
        plugin.Log.Save(@"c:\mydir\googlesearch.hwl");
 
        HttpWatch.Summary logSummary = plugin.Log.Entries.Summary;
 
        Console.WriteLine("\r\nElapsed time (secs) = " + logSummary.Time.ToString() +
                          " Downloaded bytes = " + logSummary.BytesReceived.ToString());
 
        // Uncomment the following line if you want to close
        // Internet Explorer and the console window immediately.
        //ie.Close();
    }
  }
}

The only non-trivial step required to add HttpWatch support, was to supply an IWebBrowser2 interface to the Attach method. This was achieved using the cast shown below:

HttpWatch.Plugin plugin = ct.IE.Attach((SHDocVw.IWebBrowser2)ie.InternetExplorer);

One problem you may run into is that WatiN does not work correctly with IE 7 Protected Mode on Vista. However, you can work around this by creating the instance of IE with HttpWatch and then attaching WatiN as shown below:

// This code works with WatiN version 1.3
using System;
using WatiN.Core;
 
namespace WatiNTest
{
  class WatiNTestWithHttpWatch
  {
    [STAThread]
    static void Main(string[] args)
    {
        // Create a new instance of IE with HttpWatch to avoid Protected Mode
        // issues
        HttpWatch.Controller ct = new HttpWatch.Controller();
        HttpWatch.Plugin plugin = ct.IE.New();
 
        // Attach WatiN to this instance of IE
        IE ie = IE.AttachToIE(Find.By("hwnd", plugin.Container.HWND.ToString()));
        ie.GoTo("http://www.google.com");
        plugin.Record();
 
        // Find the search text field and type Watin in it.
        ie.TextField(Find.ByName("q")).TypeText("WatiN");
 
        // Click the Google search button.
        ie.Button(Find.ByValue("Google Search")).Click();
        ie.WaitForComplete();
 
        // Stop recording and save an HttpWatch log file
        plugin.Stop();
 
        // If you are saving from protected mode IE 7 on Vista
        // you will need to use a location that is accessible from protected mode
        //plugin.Log.Save(@"C:\Users\\AppData\Local\Temp\low\googlesearch.hwl");
 
        HttpWatch.Summary logSummary = plugin.Log.Entries.Summary;
 
        Console.WriteLine("\r\nElapsed time (secs) = " + logSummary.Time.ToString() +
                          " Downloaded bytes = " + logSummary.BytesReceived.ToString());
 
        // Uncomment the following line if you want to close
        // Internet Explorer and the console window immediately.
        //ie.Close();
    }
  }
}

If you would like to try this out for yourself you would need to:

  1. Download and install HttpWatch. These samples will work with the free Basic Edition
  2. Download and install WatiN 1.3 (not 2.0 Beta)
  3. Build a .Net project using the C# code shown above
  4. Set a reference to the WatiN assembly as shown here
  5. Set a reference to the HttpWatch Automation library as described in Automating HttpWatch with Visual Basic
  6. Compile and the run the sample

UPDATE: See ‘Using HttpWatch with WatiN 2.1‘ for information about using the updated version of WatiN

Ready to get started? TRY FOR FREE Buy Now