I am trying to measure the throughput of a simple Node.js program with a CouchDB backend using cradle as the DB driver. When I put load against the program I get the following error within 30 seconds:
EADDRINUSE, Address already in use
Here is my program:
var http = require ('http'),
url = require('url'),
cradle = require('cradle'),
c = new(cradle.Connection)('127.0.0.1',5984,{cache: false, raw: false}),
db = c.database('testdb'),
port=8081;
http.createServer(function(req,res) {
var id = url.parse(req.url).pathname.substring(1);
db.get(id,function(err, doc) {
res.writeHead(200,{'Content-Type': 'application/json'});
res.write(JSON.stringify(doc));
res.end();
});
}).listen(port);
console.log("Server listening on port "+port);
I am using a JMeter script with 50 concurrent users. The average response time is 120ms, average size of the document returned 3KB.
As you can see I set the caching of Cradle to false. To investigate I looked at the number of waiting sockets: It increases up to about 4000, at which point it crashes (netstat | grep WAIT | wc -l)
To test other options I set the caching to true. In this case the program doesn't crash, but the number of waiting sockets increases to almost 10000 over time.
I also wrote the same program (sans the asynchronous part) as a Java Servlet, and it runs fine without the number of waiting sockets increasing much beyond 20.
My question is: Why do I get the ' EADDRINUSE, Address already in use' error? Why is the number of waiting sockets so high?
P.S.: This is a snippet from the output of netstat|grep WAIT:
tcp4 0 0 localhost.5984 localhost.58926 TIME_WAIT
tcp4 0 0 localhost.5984 localhost.58925 TIME_WAIT
tcp4 0 0 localhost.58924 localhost.5984 TIME_WAIT
tcp4 0 0 localhost.58922 localhost.5984 TIME_WAIT
tcp4 0 0 localhost.5984 localhost.58923 TIME_WAIT