Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS stops responding after 11 requests

Tags:

node.js

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.

like image 760
Elendir Avatar asked Oct 19 '11 18:10

Elendir


People also ask

How many concurrent requests can NodeJS handle?

js can handle ~15K requests per second, and the vanilla HTTP module can handle 70K rps.

Can NodeJS handle multiple requests?

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.

How many threads can NodeJS handle?

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.

How much RAM is required for node JS?

At least 2GB of RAM.


1 Answers

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.

like image 180
Elendir Avatar answered Sep 28 '22 11:09

Elendir