In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
It is believed that many inexperienced people are at a loss about how to solve the failure of the maximum number of connections setting in MongoDB. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Case reappearance
The following are the parameters configured for this test MongoDB case.
Check the maximum number of connections after startup.
Run the command: db.serverStatus () .connections
Current represents the number of connections currently running on the instance.
Available indicates the number of concurrent connections that the current instance can also support.
In other words, the maximum number of concurrent connections that this instance can support is: Current+available=3+816=819.
Therefore, the maxConns parameter set is invalid. So the maxConns parameter set is invalid! So the maxConns parameter set is invalid! So the maxConns parameter set is invalid!
Search for answers
At this time, check the relevant information on the Internet, most of which focus on the maximum number of file descriptors in the Linux system. Check our system configuration, it is already 65535 at this time. It is not limited by the maximum number of file descriptors in the system.
Take a turn, because our operating system is centos 7, so our mongodb service is managed through systemctl. What if the service is managed through the service command?
Test 1 Test uses service to manage the impact of mongodb services on the maximum number of connections
(1) create a service named mongodbtest0903 under the / etc/init.d directory
(2) the service is configured as follows:
(3) Grant execution permission, and then enable the service
(4) the number of connections viewed at this time is 2500 (the value of the maxConns parameter)
(5) disable mongodb service
The above description uses service to manage services, and the maximum number of connections parameter works.
Test 2 what if you open it directly with Mongodb command?
(1) directly open
(2) the number of connections viewed at this time is 2500 (the value of maxConns parameter)
(3) disable this service
The above description enables the Mongodb service directly, and the maximum number of connections parameter works.
Start the service through the service and mongodb commands, and the maximum number of connections is set, while turning on the service through systemctl becomes the default 819. 9.
Inquiry
Let's analyze the mongodb service enabled by systemctl (this service is defined as mongodbtest0903).
(1) commands to view all configuration details of this service
Systemctl show mongodbtest0903.service
Some of the details are as follows
At this time LimitNOFILE=4096
(2) View the process of this service and the resource restrictions under this process
Resource constraints for the process
Finally, I see that the resource limit is 1024.
Question1: why the mongodb service started by systemctl becomes the default 819. 0.
Answer: because the maximum number of file descriptors for service processes started by systemctl has become 1024. 102480% = 819.2, take the integer 819.
Question 2: why the maximum setting of the system is 65525 and the systemctl becomes 1024.
In Centos7 systems, Systemd is used instead of the previous SysV. The configuration scope of the / etc/security/limits.conf file has been narrowed. The configuration of / etc/security/limits.conf is only applicable to the resource restrictions of users logged in through PAM authentication, and it does not take effect on the resource restrictions of systemd's service.
In fact, a careful look at the comments in the / etc/security/limits.conf file shows that the system service does not work.
Solution
Solution, knowing what the problem is, it is relatively easy to find a solution to this problem.
Solution 1: services managed for a single systemctl.
Find specific services in / lib/systemd/system and add
# (open files) LimitNOFILE=64000
Orders. After modification, it is:
Restart the service, and the maximum number of connections is 2500, reaching the set parameters.
Solution 2 there is a solution on the Internet to modify the systemd globally. This scheme has not been verified by the author, which is recited as follows, which means that you can modify / etc/systemd/system.conf:
Global configuration, in the files / etc/systemd/system.conf and / etc/systemd/user.conf. At the same time, all .conf files / etc/systemd/system.conf.d/*.conf and / etc/systemd/user.conf.d/*.conf in the two corresponding directories are loaded
System.conf is used by the system instance and used by the user.conf user instance. For general sevice, you can use the configuration in system.conf. The configuration in systemd.conf.d/*.conf overrides system.conf.
DefaultLimitCORE=infinity
DefaultLimitNOFILE=100000
DefaultLimitNPROC=100000
Note: after the system.conf is modified, the system needs to be rebooted to take effect.
Because the systemctl on the server will manage a variety of services, in order to reduce the impact on other services, it is recommended to modify a single service, set to adopt the first scheme.
Other related knowledge
(1) mysql services will encounter similar problems.
(2) * nofiles-soft limit on the number of file descriptors a process may have
(3) * the difference between soft limit and hard limit: soft limit is the limit value that really takes effect, while hard limit is only an upper limit of the adjustment range of soft limit.
Optimization of number of connections:
Query the number of connections through serverStatus:
Mongo > db.serverStatus (). Connections
Each connection is a thread, and the default Stack setting under Stack,Linux is generally large:
Shell > ulimit-a | grep stack stack size (kbytes,-s) 10240
As for the actual Stack size used by MongoDB, you can confirm it with the following command (in K):
Shell > cat / proc/$ (pidof mongod) / limits | grep stack | awk-F 'size'' {print int ($NF) / 1024}'
If the Stack is too large (for example, 10240K), it doesn't make sense, simply compare the Size and Rss in the command results:
Shell > cat / proc/$ (pidof mongod) / smaps | grep 10240-A 10
The memory consumed by all connections can add up to a staggering amount. It is recommended to set the Stack smaller, such as 1024:
Shell > ulimit-s 1024 after reading the above, do you know how to solve the failure of the maximum number of connections setting in MongoDB? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.