mongodb 和最大连接数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8439639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:21:52  来源:igfitidea点击:

mongodb & max connections

mongodbconnection

提问by carmelo arena

i am going to have a website with 20k+ concurrent users.

我将拥有一个拥有 20k+ 并发用户的网站。

i am going to use mongodb using one management node and 3 or more nodes for data sharding.

我将使用 mongodb,使用一个管理节点和 3 个或更多节点进行数据分片。

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.

先感谢您。

回答by EhevuTov

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.

您不希望每次有新用户连接时都打开一个新的数据库连接。我不知道您是否能够轻松扩展到 20k+ 并发用户,因为 MongoDB 为每个新连接使用一个新线程。您希望您的 Web 应用程序后端只打开一到几个数据库连接,并且只在池中使用这些连接,特别是因为 Web 使用是非常异步和事件驱动的。

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

见: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.

服务器将为每个 TCP 连接使用一个线程,因此强烈建议您的应用程序使用某种连接池。幸运的是,大多数司机在幕后为你处理这个问题。一个值得注意的例外是您的应用程序为每个请求生成一个新进程的设置,例如 CGI 和一些 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.

无论您使用什么驱动程序,您都必须了解它们如何处理连接以及它们是否池化。例如,Node 的 Mongoose 是非阻塞的,因此通常每个应用程序使用一个连接。这可能是您想要的类型。