Title: mongodb & max connections
Tags: mongodb;connection
Question: i am going to have a website with 20k+ concurrent users.
i am going to use mongodb using one management node and 3 or more nodes for data sharding.
now my problem is maximum connections. if i have that many users accessing the database, how can i make sure they don't reach the maximum limit? also do i have to change anything maybe on the kernel to increase the connections?
basically the database will be used to keep hold of connected users to the site, so there are going to be heavy read/write operations.
thank you in advance.
Comment: use persistant connections, avaialable in most mongodb drivers.

Comment: It would help quite a bit to know your preferred stack (LAMP/PHP/Perl/Python/Ruby on Rails/Apache/Tomcat/Windows/Linux?)

Here is the accepted answer: 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.
Comment for this answer: thanks for your answer, now, I am total noob.. What is this driver you are talking about? how can I set it up? thank you
Comment for this answer: I know it has been a while since you answered this question, but could you provide any more insight into what a "connection" is? Is it the act of performing a query or writing data to the DB, or is it calling the connection function and passing the database URL? I'm using Mongoose, so are you saying that Mongoose only opens one connection per instance of the app, meaning that even if I had 500 users performing concurrent operations (like querying for data), then Atlas would still only see that as one connection, even when the server is hosted on Heroku? Thank you.
Comment for this answer: @enrico Well, the programming model you want to use is event-based programming and not the thread-based model you were thinking of. Node.js+Express+Mongoose+MongoDB is a popular stack for this. If you're into Perl, look into Mojolicious or AnyEvent. The problem you will run into if you don't use an evented system, is the C10k problem: http://www.kegel.com/c10k.html
I have an example of a Node.js web app here: http://github.com/EhevuTov/netPeek


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2011:00:12/09/11', 'FavoriteCount': 6.0, 'PostTypeId': 1, 'Tags': '<mongodb><connection>', 'Title': 'mongodb & max connections', 'ViewCount': 44840, 'id': 8439639, 'user_AboutMe': '', 'user_AccountId': 1089470.0, 'user_DisplayName': 'carmelo arena', 'user_Reputation': 551.0, 'user_Views': 41.0, 'user_id': 1084439.0}}