3

I am about to implement a internet connection speedtest in our web application. There is no requirement that it has to be a very advanced feature so I started to make it as simple as I could.

The idea is to fetch some data from a HttpHandler and see how long time it takes and then calculate the speed from the amount of data and the time. I thought it is better to send lets say maybe ten packages of data and throw away highest and lowest time and then calculate average time.

My HttpHandler:

public class SpeedTest : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        var Response = context.Response;

        FileInfo file = new FileInfo(@"C:\dev\Project\****\trunk\Application\1mb.txt");

        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.WriteFile(file.FullName);
            Response.End();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

Here is my jquery code that adds button and displays a dialog where I will present the results etc.

$(document).ready(function () {
$('<a href="#">Speedtest</a>').prependTo('#HeaderInfoBarRight').button({
    text: false, icons: { primary: "ui-icon-clock" }
})
    .click(function () {
        var dialog = $('<div></div>').dialog({
            autoOpen: false
            , title: 'Speedtest'
            , modal: true
            , width: 'auto'
            , resizable: false
            , height: 'auto'
            , minHeight: 50
            , close: function () {
                $(this).dialog('destroy').remove();
            }
        });
        var html = '<div>To start the test click below.</div>' +
            '<a href="#">Start test</a>';
        dialog.html(html).dialog('open');
        dialog.find('a').button({ text: true })
        .click(function () {
            var startTest = new Date();
            $.post('SpeedTest.ashx', {}, function (result) {
                var endTest = new Date();
                //Calculate time
            });
        });
    });

});

The file 1mb.txt was created through command prompt in windows as:

fsutil file createnew c:\temp\1mbfile.txt 1048576

The file is exactly 1mb. Now to the problem. When I inspect the response in for example firebug it is only 8.8 kb in size. How is this possible? Is it GZIP compression? How can it compress a 1mb file to 8.8 kb? Is it because when you create a file with fsutil the data is to repetitive?

A solution I search for is a way to force it to not compress (if this is the problem), is that possible? I can't find a way to set correct headers to not compress.

If it is a compression problem and there is nothing to do about it, can I check the response size and always count on it to be exactly that size in all environments?

Any other ideas are welcome. Also ideas over how to implement the speedtest in general if there are ideas like that.

John
  • 2,043
  • 5
  • 28
  • 49

2 Answers2

1

Yes, it could be a gzip compression issue. fsutil file createnew creates a file that consists of zeroes, so it would of course compress very efficiently.

It's possible to use the Fiddler web debugging proxy to verify whether your web server is using compression, described in this article: HTTP Compression in IIS 6 and IIS 7

Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
  • Thank you for the answer. One problem though. I don't want to turn off the compression on the web server since I need it for performance. I only want to turn it off for this explicit request. Do you know if this is possible? – John May 17 '11 at 06:25
  • If you send the HTTP header `Accept-Encoding: ` without a value it might coerce the server into sending you an uncompressed response. Or, there might a setting in your browser's about:config page that'll disable this header. – Chris Fulstow May 18 '11 at 03:35
0

Definitely it's a compression issue. as a workaround which I didn't try but I think it should work, change the extension of your generated file to something that Gzip will avoid (ex: mp3) and try your test again and see if it get compressed again or not.

let me know what happened, thanks.

Mohammed Swillam
  • 9,119
  • 4
  • 36
  • 47