简体   繁体   中英

Mongodb - replica set - max connections

I have a replicaset of 3 mongo node, 1 primary, 1 secondary and 1 arbiter.

Connected on this replicaset, i have 20 node process, on 20 different serveur using their own connections to the replicaset. All those process use mongoose.

My primary replicaset show the following :

rsProd:PRIMARY> db.serverStatus().connections
{ "current" : 284, "available" : 50916, "totalCreated" : NumberLong(42655) }

From time to time, when i restart some nodejs node i have the following errors :

mongodb no valid seed servers in list

My connection string to the replicaset is the following :

"mongodb://mongo2aws.abcdef:27017/dbname,mongo1.abcdef:27017/dbname"

And my db options are the following :

       config.db_options = {
            user:           "MYUSER",
            pass:           "MYPASSWORD",
            replset: {
                rs_name:    "RSNAME",
                ssl:        true,
                sslValidate:false,
                sslCA:      ca,
                ca:         ca,
                sslKey:     key,
                sslCert:    key
            },
            socketOptions : {
                keepAlive :         1,
                connectTimeoutMS :  1000
            },
            server: {
                ssl:        true,
                sslValidate:false,
                sslCA:      ca,
                ca:         ca,
                sslKey:     key,
                sslCert:    key
            },
            auth: {
                authdb: 'MYAUTHDB'
            }
        };

I haven't this error when i was running only 16 node process. According to this i suppose that i have reach a limit of max concurrent connections or something like this.

But, if i restart again crashing node, it finally seems to work.

Why mongo / mongoose raise this error ? What can i do to prevent this / increase limit ?

Thanks in advance Best regards.

Solved by increasing ulimit open files

Default ulimit for open files in AWS EC2 ubuntu server is set to 1000 by default.

In addition, adding reconnect options prevent this problem :

config.db_options.reconnectTries=10;
config.db_options.reconnectInterval=500;
config.db_options.poolSize=20;
config.db_options.connectTimeoutMS=5000;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM