question about ReplSet haInterval param

10 views
Skip to first unread message

赵玄

unread,
Jan 27, 2016, 10:16:29 PM1/27/16
to node-mongodb-native
hi Christian

I was just doing a study of the mongodb drivers about replset, this is my demo

 

var MongoClient = require('mongodb').MongoClient;

var Logger = require('mongodb').Logger;

var url = 'mongodb://10.21.3.44:30000/haozxuan';


Logger.setLevel('debug');

MongoClient.connect(url, /*{"replSet": {"haInterval": 1000}},*/ function (err, db) {

    if (err) console.log('err is ', err);

    var collection = db.collection('test');


    setInterval(function () {

        collection.findOne({}, function (err, res) {

            console.log('res is ',new Date(), res);

        })

    }, 1000)

})


i have a replset, info 

primary 10.21.3.44:30000

secondary 10.21.3.44:30001

secondary 10.21.3.44:30002

arbiter 10.21.3.44:30003


when i  run  db.shutdownServer, i catch this result:

res is  Thu Jan 28 2016 10:18:06 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:07 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:08 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:09 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:10 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:11 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:13 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:14 GMT+0800 (CST) null

res is  Thu Jan 28 2016 10:18:15 GMT+0800 (CST) null


however, in this page(A) http://mongodb.github.io/node-mongodb-native/2.0/api/ReplSet.html, the parma haInterval default is 5000ms. 

and then , i find mort info in this page(B) https://github.com/christkv/mongodb-core/blob/master/lib%2Ftopologies%2Freplset.js#L138

is this something wrong in page A?


and how much the haInterval of suitable? 10s too long? or 1s too short.  i think too short  have affect mongo server, too long have affect my application.i am confuse about that.


Regards 

haozxuan

Christian Kvalheim

unread,
Jan 28, 2016, 3:25:45 AM1/28/16
to node-mongodb-native
Will update the docs the right value is in fact 10000

It's fine, haInterval affects mainly finding new servers only, if a server closes it's connection discovery uses the minHeartbeatFrequencyMS value to quickly attempt to establish the connection.

You can play around with the haInterval if you feel like it but 10 sec is a good trade off for most situations like elections of a new primary.
Reply all
Reply to author
Forward
0 new messages