23

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.

carmelo arena
  • 551
  • 1
  • 4
  • 15

1 Answers1

25

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.

EhevuTov
  • 20,205
  • 16
  • 66
  • 71
  • 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 – carmelo arena Dec 09 '11 at 13:10
  • 2
    @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 – EhevuTov Dec 09 '11 at 16:47
  • 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. –  Apr 28 '19 at 05:59