Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8188891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:04:17+00:00 2026-06-07T03:04:17+00:00

Just started testing nodejs, and wanted to get some help in understanding following behavior:

  • 0

Just started testing nodejs, and wanted to get some help in understanding following behavior:

Example #1:

var http = require('http');
http.createServer(function(req, res){
    res.writeHeader(200, {'Content-Type': 'text/plain'});
    res.end('foo');
}).listen(1001, '0.0.0.0');

Example #2:

var http = require('http');
http.createServer(function(req, res){
    res.writeHeader(200, {'Content-Type': 'text/plain'});
    res.write('foo');
    res.end('bar');
}).listen(1001, '0.0.0.0');

When testing response time in Chrome:

example #1 – 6-10ms
example #2 – 200-220ms

But, if test both examples through nginx proxy_pass

server{
    listen 1011;
    location / {
        proxy_pass http://127.0.0.1:1001;
    }
}

i get this:

example #1 – 4-8ms
example #2 – 4-8ms

I am not an expert on either nodejs or nginx, and asking if someone can explain this?

nodejs – v.0.8.1
nginx – v.1.2.2

update:

thanks to Hippo, i made test with ab on my server with and without nginx,
and got opposite results.

also added to nginx config proxy_cache off

server{
    listen 1011;
    location / {
        proxy_pass http://127.0.0.1:1001;
        proxy_cache off;
    }
}

example #1 direct:

ab -n 1000 -c 50 http:// 127.0.0.1:1001/


    Server Software:        
    Server Hostname:        127.0.0.1
    Server Port:            1001

    Document Path:          /
    Document Length:        65 bytes

    Concurrency Level:      50
    Time taken for tests:   1.018 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      166000 bytes
    HTML transferred:       65000 bytes
    Requests per second:    981.96 [#/sec] (mean)
    Time per request:       50.919 [ms] (mean)
    Time per request:       1.018 [ms] (mean, across all concurrent requests)
    Transfer rate:          159.18 [Kbytes/sec] received

    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.6      0       3
    Processing:     0   50  44.9     19     183
    Waiting:        0   49  44.8     17     183
    Total:          1   50  44.7     19     183

example #1 nginx:

ab -n 1000 -c 50 http:// 127.0.0.1:1011/


    Server Software:        nginx/1.2.2
    Server Hostname:        127.0.0.1
    Server Port:            1011

    Document Path:          /
    Document Length:        65 bytes

    Concurrency Level:      50
    Time taken for tests:   1.609 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      187000 bytes
    HTML transferred:       65000 bytes
    Requests per second:    621.40 [#/sec] (mean)
    Time per request:       80.463 [ms] (mean)
    Time per request:       1.609 [ms] (mean, across all concurrent requests)
    Transfer rate:          113.48 [Kbytes/sec] received

    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.6      0       3
    Processing:     2   77  44.9     96     288
    Waiting:        2   77  44.8     96     288
    Total:          3   78  44.7     96     288

example #2 direct:

ab -n 1000 -c 50 http:// 127.0.0.1:1001/


    Server Software:        
    Server Hostname:        127.0.0.1
    Server Port:            1001

    Document Path:          /
    Document Length:        76 bytes

    Concurrency Level:      50
    Time taken for tests:   1.257 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      177000 bytes
    HTML transferred:       76000 bytes
    Requests per second:    795.47 [#/sec] (mean)
    Time per request:       62.856 [ms] (mean)
    Time per request:       1.257 [ms] (mean, across all concurrent requests)
    Transfer rate:          137.50 [Kbytes/sec] received

    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.3      0       2
    Processing:     0   60  47.8     88     193
    Waiting:        0   60  47.8     87     193
    Total:          0   61  47.7     88     193

example #2 nginx:

ab -n 1000 -c 50 http:// 127.0.0.1:1011/


    Server Software:        nginx/1.2.2
    Server Hostname:        127.0.0.1
    Server Port:            1011

    Document Path:          /
    Document Length:        76 bytes

    Concurrency Level:      50
    Time taken for tests:   1.754 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      198000 bytes
    HTML transferred:       76000 bytes
    Requests per second:    570.03 [#/sec] (mean)
    Time per request:       87.715 [ms] (mean)
    Time per request:       1.754 [ms] (mean, across all concurrent requests)
    Transfer rate:          110.22 [Kbytes/sec] received

    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.4      0       2
    Processing:     1   87  42.1     98     222
    Waiting:        1   86  42.3     98     222
    Total:          1   87  42.0     98     222

Now results looks more logic, but still there is a strange delay when calling res.write()

I guess it was (sure looks like) a stupid question, but i still get huge difference in response time in browser with this server configuration (Centos 6) and this concrete server (vps).

On my home computer (Ubuntu 12) but with older versions testing from localhost everything works fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:04:18+00:00Added an answer on June 7, 2026 at 3:04 am

    Peeking into http.js reveals that case #1 has special handling in nodejs itself, some kind of a shortcut optimization I guess.

    var hot = this._headerSent === false &&
                typeof(data) === 'string' &&
                data.length > 0 &&
                this.output.length === 0 &&
                this.connection &&
                this.connection.writable &&
                this.connection._httpMessage === this;
    
          if (hot) {
            // Hot path. They're doing
            //   res.writeHead();
            //   res.end(blah);
            // HACKY.
    
            if (this.chunkedEncoding) {
              var l = Buffer.byteLength(data, encoding).toString(16);
              ret = this.connection.write(this._header + l + CRLF +
                                          data + '\r\n0\r\n' +
                                          this._trailer + '\r\n', encoding);
            } else {
              ret = this.connection.write(this._header + data, encoding);
            }
            this._headerSent = true;
    
          } else if (data) {
            // Normal body write.
            ret = this.write(data, encoding);
          }
    
          if (!hot) {
            if (this.chunkedEncoding) {
              ret = this._send('0\r\n' + this._trailer + '\r\n'); // Last chunk.
            } else {
              // Force a flush, HACK.
              ret = this._send('');
            }
          }
    
          this.finished = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started out with testing some php mvc framework In it, it
I've just started doing some real-world performance testing on my Fluent NHibernate / SQLite
I had just started working on some automated testing tools, namely test complete, which
I've just started trying to set up some unit testing in what is essentially
I've just started doing some PowerShell scripting, and I'm running into a problem testing
I've just started testing some upload utility i've built and put 47 items for
I've just recently started using unit testing, and I understand some of the main
I've just started testing the water with WPF and I'm trying to bind the
I've just started messing around with php recently and I was testing my new
I am just getting started with JS Unit Testing and am trying out qUnit.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.