http.createServer(function(request, response) {
console.log("New request :"+request.url);
var found = false;
for(var i= 0; i < requests.length; i++){
match = requests[i];
if(match.method == request.method && request.url.match(match.regexp))
{
console.log("Matched request: "+match.url);
pg.connect(databaseUrl, function(error, client) {
if(error)
processError(response, error);
else
match.action(client, request, response);
});
found = true;
break;
}
}
if(!found)
processError(response, "Request url does not exist: "+request.url);
}).listen(3000);
sys.puts("Server running... waiting for requests");
Hi everyone. I'm stuck with this code. Whenever I call 11 times the same request, nodejs stops responding and does not even logs "New request: "+request.url. Anyone has an idea of what's going on ?
Thanks a lot.
js can handle ~15K requests per second, and the vanilla HTTP module can handle 70K rps.
How NodeJS handle multiple client requests? NodeJS receives multiple client requests and places them into EventQueue. NodeJS is built with the concept of event-driven architecture. NodeJS has its own EventLoop which is an infinite loop that receives requests and processes them.
As nodejs works on event loop and it will assign the IO operation to thread pool, but thread pool default size is 4, so at same time maximum 4 thread (IO operation) can work and rest has to wait in queue. Once any thread complete the execution, they can process.
At least 2GB of RAM.
Sorry for the late come back. I found what was the problem but don't completely understand it. In the connect loop, I was using functions which were actually only simulating values (normally captured by a request). This was the problem. If you don't issue any database request in the pg.connect and loop on it, it seems the connections do not close properly. So the connection pool apparently breaks. Hope I've been clear enough.
Anyway thank you for your help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With