mongodb :增加 mongodb 中的最大连接数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16713415/
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 13:14:32  来源:igfitidea点击:

mongodb : Increasing max connections in mongodb

mongodb

提问by

i need your help in solving this

我需要你的帮助来解决这个问题

this is the result of my ulimit -aon my linux server

这是我ulimit -a在我的 linux 服务器上的结果

   core file size          (blocks, -c) 0
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 10000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 24576
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Right now this is the result of my MongoDB

现在这是我的 MongoDB 的结果

db.serverStatus().connections

{ "current" : 4, "available" : 5996 }

I want to increase the MongoDb connections more to 10000 .

我想将 MongoDb 连接增加到 10000 。

I have tried different options like in my mongod1.conf

我尝试了不同的选项,比如在我的 mongod1.conf

fork    = true
port    = 27017
maxConns = 10000

and also this while starting mongodb

还有这个同时启动mongodb

mongod ulimit -n 10000  --config mongod1.conf 

but nothing worked and all failed , please let me know how can i increase the connections to 10000 in my case , thanks in advance .

但没有任何效果,一切都失败了,请让我知道如何将连接增加到 10000,在此先感谢。

回答by Kashyap

You also need bump up the number of file descriptors and number of file descriptors per process that the Linux kernel allows.

您还需要增加 Linux 内核允许的文件描述符数量和每个进程的文件描述符数量。

In Linux, this should be configured by editing the file at /proc/sys/fs/file-maxor by the sysctlutility.

在 Linux 中,这应该/proc/sys/fs/file-max通过在sysctl实用程序处或由实用程序编辑文件来配置。

  • Edit the /etc/sysctl.conffile and add fs.file-max = 50000. This sets the maximum file descriptors that can run as a system-wide limit.
  • Running ulimit -n 50000sets the user-wide limit for the maximum number of file descriptors open.
  • 编辑/etc/sysctl.conf文件并添加fs.file-max = 50000. 这将设置可以作为系统范围限制运行的最大文件描述符。
  • 运行ulimit -n 50000为打开的最大文件描述符数设置用户范围的限制。

Check this link for a more descriptive write-up for editing the limits on a linux machine: http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

检查此链接以获取有关编辑 linux 机器限制的更具描述性的文章:http: //www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

回答by rustyx

Have you tried:

你有没有尝试过:

--maxConns arg       max number of simultaneous connections

(Source: mongoddocumentation)

(来源:mongod文档)

回答by David Valdivieso

Method 1If you use systemd(systemctl restart mongod)

方法一如果使用systemd( systemctl restart mongod)

sudo mkdir /etc/systemd/system/mongod.service.d/
sudo vi /etc/systemd/system/mongod.service.d/limits.conf

then add:

然后加:

[Service]
LimitFSIZE=infinity
LimitCPU=infinity
LimitAS=infinity
LimitMEMLOCK=infinity
LimitNOFILE=64000
LimitNPROC=64000

Then execute:

然后执行:

systemctl daemon-reload
systemctl restart mongod

Method 2If NO systemd(service mongod restart)

方法 2如果没有systemd( service mongod restart)

sudo vi /etc/security/limits.d/99-mongodb.conf

Add something like:

添加如下内容:

*       -       nproc   64000
*       -       nofile  64000
*       -       fsize   unlimited
*       -       cpu     unlimited
*       -       memlock unlimited
*       -       as      unlimited
*       -       rss     unlimited

Note that * it's a wildcard. But you could use a specific user or group. Then restart session and mongod.

请注意 * 它是一个通配符。但是您可以使用特定的用户或组。然后重新启动会话和 mongod。

回答by Zihao Zhao

It seems MongoDB has no limit on incoming connections and you should modify system-wide limit, see official doc:

似乎 MongoDB 对传入连接没有限制,您应该修改系统范围的限制,请参阅官方文档:

Unless constrained by system-wide limits, MongoDB has no limit on incoming connections. On Unix-based systems, you can modify system limits using the ulimitcommand, or by editing your system's /etc/sysctlfile. See UNIX ulimit Settingsfor more information.

除非受系统范围限制,否则 MongoDB 对传入连接没有限制。在基于 Unix 的系统上,您可以使用该ulimit命令或通过编辑系统/etc/sysctl文件来修改系统限制。有关详细信息,请参阅UNIX ulimit 设置

Recommended ulimit Settings(offical doc):

推荐的 ulimit 设置(官方文档):

-f (file size): unlimited

-t (cpu time): unlimited

-v (virtual memory): unlimited

-n (open files): 64000

-m (memory size): unlimited

-u (processes/threads): 64000

-f(文件大小):无限制

-t (cpu 时间): 无限制

-v(虚拟内存):无限制

-n(打开文件):64000

-m(内存大小):无限制

-u(进程/线程):64000

Remember to restartyour mongodand mongosinstances after changing the ulimit settings to ensure that the changes take effect.

请记住在更改 ulimit 设置后重新启动您的mongodmongos实例以确保更改生效。

Source: number-of-connectionsrecommended-ulimit-settings

来源: 推荐的连接数-ulimit-settings

回答by Tyler Brock

You might need to change the hard limits in /etc/limits.confor /etc/security/limits.confdepending on your distribution.

您可能需要更改硬限制/etc/limits.conf/etc/security/limits.conf根据您的分布。