Unexpected behavior when increasing network speed and connecting to a node.js server

I have a simple node.js server like:

var app = require('express')();
var compression = require('compression');
app.use(compression());

app.get("https://stackoverflow.com/", function(request, response) {
  response.send('<!DOCTYPE html>.......');
}
app.listen(2345);

The html I send is 2.4kB (1.2kB when compressed).
When testing on different network speed (using dev tools) I get this unexpected behavior:

50kbps:  Latency 600ms, download   1ms
250kbps: Latency 300ms, download 0.6ms
750kbps: Latency 100ms, download 100ms
2Mbps:   Latency  10ms, download 200ms
32Mbps:  Latency   5ms, download 210ms

I don’t think that the download time is supposed to increase when network speed increases after 250kbps. What is going on?
Again look at what happens if I remove compression:

var app = require('express')();

app.get("https://stackoverflow.com/", function(request, response) {
  response.send('<!DOCTYPE html>.......');
}
app.listen(2345);

Now the file is just 2.4kB and look at the latency/download times:

50kbps:  Latency 550ms, download 230ms
250kbps: Latency 350ms, download  50ms
750kbps: Latency 120ms, download  15ms
2Mbps:   Latency  35ms, download   6ms
32Mbps:  Latency   4ms, download 0.5ms

The response with the non-gzipped content (and contet-length header) seems to be ok, but the response with the gzipped content (with transfer-encoding chunked header) doesn’t seem to be ok.
What is this all about?
I strongly encourage you to simulate a similar test yourself with whatever tools you like and see the results yourself before saying that my benchmark is wrong and that this cannot be possible. And if you get different results please share them.

Express.js compression options

I would also not hesitate to change the different compression quality settings, strategies and especially the treshold setting of the express compression module, as described here: https://github.com/expressjs/compression, especiall the:

Compression Treshold Level

Since you are sending only a few bytes of textual data as body, try to set the treshold lower then the default of 1Kb.

The byte threshold for the response body size before compression is considered for the response, defaults to 1kb. This is a number of bytes, any string accepted by the bytes module, or false.

(cited from the express compression module github page)

HTTP Compression is not always faster

Make sure to play around with other HTTP features like HTTP Pipelining or accepted encodings (also on the client side) as switching those on or off may vastly alter the outcome of download time.

Read More:   How make promise execute synchronously?

IBM conducted a series of excellent HTTP tests which I recommend you read about here: http://www.ibm.com/developerworks/library/wa-httpcomp/


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Similar Posts