Correct setting method of ulimit value in Linux system

Time:2020-8-14

When learning swoole, there is a max_ Conn parameter,

max_conn

Description: the maximum number of TCP connections the server is allowed to maintain

Note: after setting this parameter, when the number of existing connections reaches this value, new connections will be rejected. In addition, the value of the parameter cannot exceed the value of ulimit – n of the operating system, and the value should not be set too large, because of the tool_ The server will request a large amount of memory at a time to store the information of each connection. This value will also affect the maximum number of concurrent servers. In fact, Linux has file handle restrictions, and Linux is not very high by default, which is usually 1024. Production servers can easily reach this number.

  The steps to set the ulimit – n value of Linux correctly are as follows:

1. Use the command ulimit – n to check the current value

  2. vim /etc/security/limits.conf

It is recommended to set both of the following to 65535

    * soft nofile 65535

    * hard nofile 65535

(the * asterisk in front represents global, for all users; nofile represents the number of file handles; the value of soft nofile cannot exceed the value of hard nofile)

3. Restart the Linux system

Command: shutdown – r now means to restart immediately

The method to check the number of physical CPU, core and logical CPU in Linux system is as follows:

When learning swoole, it is recommended that the number of worker processes to be started is 1-4 times of the number of CPU cores. So I learned how to check the CPU cores

#View the number of physical CPUs

cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l

#View the number of cores per physical CPU

cat /proc/cpuinfo| grep “cpu cores”| uniq

#Check the number of logical CPUs

Cat / Pro / cpuinfo | grep “processor” | WC – L ා view CPU information (model) cat / proc / cpuinfo | grep name | cut – F2 – D: | uniq – C

Recommended Today

How to share queues with hypertools 2.5

Share queue with swote To realize asynchronous IO between processes, the general idea is to use redis queue. Based on the development of swote, the queue can also be realized through high-performance shared memory table. Copy the code from the HTTP tutorial on swoole’s official website, and configure four worker processes to simulate multiple producers […]