Network transmission gets linear higher with length

6 views
Skip to first unread message

Sebastian Ühlin

unread,
Apr 27, 2016, 10:09:36 AM4/27/16
to nodejs

The goal is to deliver files with a nodejs http server.


The problem is the transmission from the server response to the browser.

I deliver a string as content as shown in program code.

VPS: debian 7 / SSD / 2 core / ~30ms ping



Some string size benchmarking (**content-download time**)


-     1 kb:     0,18 ms

-   10 kb:     7,00 ms

-   20 kb:   47,50 ms

-   30 kb:   55,00 ms

-   40 kb:   58,10 ms

-   50 kb:   86,20 ms

-   60 kb:   93,10 ms

-   80 kb: 107,10 ms

- 100 kb: 120,00 ms (nginx needs 0.31ms)


From start to finish the response in the server. it takes ~1ms no matter what file size, so the problem is between nodejs sending the files and the browser receiving the files.


Program code:

// var request => the http incoming request
request.socket.setNoDelay();
request.connection.setNoDelay();

// var response => the response from the http incoming request

response.on('close', function () {
  console.log("[ABORTED][%s] %s", request.connection.remoteAddress, request.url);
});
response.on('finish', function () {
  console.log("[SUCCESS][%s] %s", request.connection.remoteAddress, request.url);
});

// get the content of the file (takes ~0ms)
var fileContent = fileSystem.readFileSync(filePath, 'utf8');

// Configure response header
response.writeHead(200, {
  'content-length': ''+fileContent.length,
  'content-type': 'text/plain',
});

// Send content
response.end(fileContent, 'utf8', function(){
  console.log("Ending response took %sms", Date.now()-timeB2);
});
Reply all
Reply to author
Forward
0 new messages