我已经设置了带有6台服务器的MongoDB副本集,一切正常,数据被复制,没有问题。
当我从node.js直接连接到主服务器时,插入查询执行时间小于20毫秒,但是当我列出连接字符串中的所有服务器(documentation)时,查询的执行时间异常增加,范围从1.5秒到11秒。
我使用最新版本(https://github.com/mongodb/node-mongodb-native)
的原生mongodb包MongoDB版本是3.0.10。
连接字符串示例:
mongodb://s1,s2,s3,s4,s5,s6/my_database?replicaSet=repl
我尝试了各种选项,例如将写入关注设置为0(即使它在副本集配置中设置为1)和日志设置为true,但没有任何作用
即使我在连接字符串中仅使用2台服务器,执行时间仍然会增加。
副本集配置:
{
"_id" : "repl",
"version" : 7,
"members" : [
{
"_id" : 0,
"host" : "mongo1:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 2,
"tags" : {},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 1,
"host" : "mongo2:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 2,
"host" : "mongo3:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 3,
"host" : "mongo4:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 4,
"host" : "mongo5:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 5,
"host" : "mongo6:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0.5,
"tags" : {},
"slaveDelay" : 0,
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : { },
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}