Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requests and connections double on node 4.1.2

Tags:

node.js

We're currently in the process of updating from node 0.10 to node 4.1.2 and we're seeing some weird patterns. The number of connections to our postgres database doubles1 and we're seeing the same pattern with requests to external services2. We are running a clustered app running the native cluster API and the number of workers is the same for both versions.

I'm failing to understand why upgrading the runtime language would apparently change application behaviour by doubling requests to external services.

Postgres connections External requests

like image 731
Chris911 Avatar asked Oct 07 '15 13:10

Chris911


2 Answers

One of the interesting things I've noticed with 0.12 and 4.x is the change in garbage collection. I've not used the pg module before so I don't know internally how it maintains it's pools of if it would be affected by memory or garbage collection. If you haven't defined default memory setting for node you could try giving that a shot and see if you see any other results.

node --max_old_space_size <some sane value in MB>

like image 165
ambrons Avatar answered Nov 17 '22 00:11

ambrons


I ran into something similar, but I was getting double file writes. I don't know your exact case, but I've seen a scenario where requests could almost exactly double.

in the update to 4.1.2, process.send and child.send has gone from synchronous to asynchronous.

I found an issue like this:

var child = fork('./request.js');
var test = {};

child.send(small request);
child.send(large request);
child.on('response', function (val) {
    console.log('small request came back: ' + val);
    test = val;
});

if(!test){
   //retry request
} ...

So where as previously the blocking sends has allowed this code to work, the non-blocking version assumes an error has occurred and retries. No error actually occurred, so double the requests come in.

like image 42
Christian Davis Avatar answered Nov 16 '22 22:11

Christian Davis