Increase Mongodb Maximum Number of Connections

mongodb & max connections

You don't want to open a new database connection each time a new user connects. I don't know if you'll be able to scale to 20k+ concurrent users easily, since MongoDB uses a new thread for each new connection. You want your web app backend to have just one to a few database connections open and just use those in a pool, particularly since web usage is very asynchronous and event driven.

see: http://www.mongodb.org/display/DOCS/Connections

The server will use one thread per TCP
connection, therefore it is highly recomended that your application
use some sort of connection pooling. Luckily, most drivers handle this
for you behind the scenes. One notable exception is setups where your
app spawns a new process for each request, such as CGI and some
configurations of PHP.

Whatever driver you're using, you'll have to find out how they handle connections and if they pool or not. For instance, Node's Mongoose is non-blocking and so you use one connection per app usually. This is the kind of thing you probably want.

Increase MongoDB maximum number of connections

Check the MongoDB documentation:

http://www.mongodb.org/

use this command line argument:

--maxConns arg       max number of simultaneous connections

You might want to check this: http://blog.boxedice.com/2011/06/08/mongodb-connection-overhead/

Number of active connections on the server reached to max

Assuming your backend is deployed on lambda since serverless tag.

Each invocation will leave a container idle to prevent cold start, or use an existing one if available. You are leaving the connection open to reuse it between invocation, like advertised in best practices.

With a poolSize of 25 (?) and 100 max connections, you should limit your function concurrency to 4.

Reserve concurrency to prevent your function from using all the available concurrency in the region, or from overloading downstream resources.

More reading: https://www.mongodb.com/blog/post/optimizing-aws-lambda-performance-with-mongodb-atlas-and-nodejs

MongoDB available connections

For UNIX-like systems (i.e. Linux and OS X), the connection limit is governed by ulimits. MongoDB will use 80% of the available file descriptors for connections, which is why you see 203 on Mac (~80% of 256) and 819 on Linux (~80% of 1024).

The MongoDB documentation includes recommended settings for production systems. Typically you wouldn't need to change this on development environments, but you will see a warning on startup if the connection limits are considered low.

In MongoDB 2.4 and earlier, there is a hard-coded maximum of 20,000 connections per server irrespective of the ulimits. This maximum has been removed as at MongoDB 2.6.

There is also a maxConns MongoDB configuration directive that can be used to limit the connections to something lower than what would be allowed by ulimits.

MongoDB Atlas: High number of connections alert

First, make sure that your client applications are sharing the same driver client instance. Make it a singleton and reuse it, don't instantiate new clients on every request.

Next, configure the max connection pool size. The max connection count on an M2 cluster is 100 and the default for the connection pool size is 100.

You can override the value in code or directly in the connection string using the following syntax

mongodb+srv://user:password@...?&retryWrites=true&w=majority&maxPoolSize=10


Related Topics



Leave a reply



Submit