mongodb & max connections

后端 未结 1 1674
名媛妹妹
名媛妹妹 2020-12-29 05:04

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 pr

相关标签:
1条回答
  • 2020-12-29 05:26

    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.

    0 讨论(0)
提交回复
热议问题