Chris
Chris

Reputation: 4225

Low serverside CPU usage when throwing lots of node.js GET-requests at Apache Webserver

I'm currently writing a very simple load test using node.js as the test initiator and Apache as my WebServer, serving a simple http-website. If I use the following code to issue 1000 GET-requests

var options = {
  host: 'private.webserver',
  path: '/',
  port: '80',
  method: 'GET'
};
var testnr = 1000;
while(testnr--) http.request(options, function(res){cb();}).end();

It takes a pretty long time for it to finish (as expected) but on the server I only see about 10-15% CPU usage while running the test. Is their some kind of limiter active? Would I see the same behavior if i'd be using a distributed setup of node.js initiators?

Upvotes: 1

Views: 790

Answers (1)

Michelle Tilley
Michelle Tilley

Reputation: 159105

http.Agent has a maxSockets attribute that indicates how many socket connections a given agent can have open; it defaults to 5 (so you are really only making 5 HTTP requests at a time). You can modify this value on http.globalAgent, which is the agent that the http module uses by default to make HTTP requests:

http.globalAgent.maxSockets = 1000 // or as mnay as you want to handle at a time

Upvotes: 1

Related Questions