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);});

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/17d720c4-96a1-47d5-9bd2-d440fe741f1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to