mongodb&最大连接数 [英] mongodb & max connections

查看:77
本文介绍了mongodb&最大连接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立一个拥有2万以上并发用户的网站.

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

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

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.

先谢谢您

推荐答案

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

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.

请参阅: http://www.mongodb.org/display/DOCS/Connections

服务器将为每个TCP使用一个线程 连接,因此强烈建议您使用应用程序 使用某种连接池.幸运的是,大多数驾驶员都可以解决这个问题 为您在幕后.一个值得注意的例外是设置 应用会为每个请求生成一个新流程,例如CGI和一些 PHP的配置.

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.

无论使用哪种驱动程序,都必须找出它们如何处理连接以及它们是否池化.例如,Node的猫鼬是无阻塞的,因此通常每个应用程序使用一个连接.这可能就是您想要的那种东西.

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.

这篇关于mongodb&最大连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆