Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I have a simple node.js server like:

var app = require('express')(); var compression = require('compression'); app.use(compression());  app.get('/', 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('/', 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.

like image 864
Core_dumped Avatar asked Feb 17 '15 22:02

Core_dumped


People also ask

CAN node js handle high traffic?

Given its single-thread architecture, Node. js is well-suited for handling large amounts of data and traffic. Even when distributed devices are involved, Node. js performs at extremely high speeds and syncs quickly across client and server sides.

How fast is node js server?

Results will vary depending on the machine. However, considering that a “Hello World” Node. js server is easily capable of thirty thousand requests per second on that machine that produced these results, 23 requests per second with an average latency exceeding 3 seconds is dismal.

What is Node JS in networking?

Node. js (Node) is an open source development platform for executing JavaScript code server-side. Node is useful for developing applications that require a persistent connection from the browser to the server and is often used for real-time applications such as chat, news feeds and web push notifications.


1 Answers

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.

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

like image 193
stevek-pro Avatar answered Sep 21 '22 19:09

stevek-pro