[node.js] Why my request slower and slower

62 views
Skip to first unread message

jason.桂林

unread,
Apr 26, 2012, 3:07:56 AM4/26/12
to nod...@googlegroups.com
My question attached code and image, please help me on stackoverflow, thanks a lot.

http://stackoverflow.com/questions/10328492/why-my-request-slower-and-slower

--
Best regards,

Jason Green
桂林


jason.桂林

unread,
Apr 26, 2012, 3:22:49 AM4/26/12
to nod...@googlegroups.com
I am writing a http benchmark module in node.js. I got a problem. I separate my benchmark to several task to run. one task by one task. each task define like 'GET /url for 10000 times'.

My problem is, if I start a task 'GET / for 100000 times' it response in 7.2k rps. If I separate the task to 10 task, 'GET / for 10000 times', the first task response fast, but the other tasks slower and slower.

http://stackoverflow.com/questions/10328492/why-my-request-slower-and-slower

2012/4/26 jason.桂林 <gui...@gmail.com>

jason.桂林

unread,
Apr 26, 2012, 12:27:36 PM4/26/12
to nod...@googlegroups.com
fixed, my foolish mistake

2012/4/26 jason.桂林 <gui...@gmail.com>

Matt

unread,
Apr 26, 2012, 12:58:38 PM4/26/12
to nod...@googlegroups.com
Why did you remove the post though? Someone else might make the same mistake - it's always good to keep history of how you fixed it.

2012/4/26 jason.桂林 <gui...@gmail.com>

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 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 post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

mscdex

unread,
Apr 26, 2012, 1:27:54 PM4/26/12
to nodejs
On Apr 26, 12:58 pm, Matt <hel...@gmail.com> wrote:
> Why did you remove the post though? Someone else might make the same
> mistake - it's always good to keep history of how you fixed it.

+1

jason.桂林

unread,
Apr 26, 2012, 8:30:54 PM4/26/12
to nod...@googlegroups.com
OK, I explain here

the wrong code is:

function sendRequest
02      if(running > concurrent) return;
03      if(running ++ < concurrent && left >0) process.nextTick(sendRequest);
      
      http.request(reqOptions, function(res) {
           res.on('end', function() {
                 running --;
08             if(--left == 0) {
09                    nextTask()
10             }
                process.nextTick(sendRequest)
           });
      });
}

When the tasks[1] is done, means left <= 0, line 9 will call nextTask execute tasks[2], and but line 11 is still executed, and line 2 does not filter the left < 0 and continue send request, so tasks[1] and tasks[2] is both running, so the tasks[2] display rps just about half of tasks[1].

I modified 2 lines code  fixed this issue.

function sendRequest

      if(running > concurrent || left <=0) return;
      if(running ++ < concurrent) process.nextTick(sendRequest);

}

BTW: you can clone https://github.com/guileen/siege.js , run the example, I bet you will like it even it is not complete yet.

It's easy to write a benchmark module

siege(__dirname + '/app.js')
  .concurrent(100)
  .for(10000).times
  .get('/')
  .post('/')
  .attack()

It will automatic listen on a temp unix socket, if you not specify what port to listen. 

The output is colorful and real time.

Because of node.js keep alive the connections I think, I can get correct benchmark on Mac OSX now, we know that `ab` get wrong result on Mac, because of OS connections limitations I guess. What ever, I can do benchmark on Mac now.

In the plan, it will also has the feature to enable cookie, and condtional GET. maybe not now, maybe you can send a pull request.

siege(__dirname + '/app.js')
  .concurrent(100)
  .for(10000).times
.withCookie()
.with304()
.post('/login', {username:'username', password: 'password}).for(1).times
  .get('/')
  .attack()


2012/4/27 mscdex <msc...@gmail.com>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 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 post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Reply all
Reply to author
Forward
0 new messages