Home Operation and Maintenance Nginx How to optimize Nginx high concurrency kernel

How to optimize Nginx high concurrency kernel

May 15, 2023 pm 05:52 PM
nginx

What is high concurrency

  • The default Linux kernel parameters consider the most common scenarios and are not suitable for web applications that support high concurrent access. server, so you need to modify the Linux kernel parameters, so that nginx can have higher performance; To make adjustments, when nginx is used as a static web content server, a reverse proxy, or a server that provides a compression server, the adjustments to the kernel parameters are different. Here are the most common TCP network parameters that enable nginx to support more concurrent requests. Make simple configurations;

  • These require modifying /etc/sysctl.conf to change the kernel parameters.

  • Configuration method


Configuration detailed analysis

#Indicates that a single process is large The number of handles that can be opened; the

fs.file-max = 999999
Copy after login
# parameter is set to 1, which means that the socket in the time_wait state is allowed to be reused for a new tcp link. This is of great significance to the server because there are always a large number of links in the time_wait state. Exists;

net.ipv4.tcp_tw_reuse = 1
Copy after login

#When keepalive is started, the frequency of tcp sending keepalive messages; the default is 2 hours, setting it to 10 minutes can clean up invalid links faster.

ner.ipv4.tcp_keepalive_time = 600
Copy after login

#When the server actively closes the link, the maximum time the socket remains in the fin_wait_2 state

net.ipv4.tcp_fin_timeout = 30
Copy after login

#This parameter indicates the maximum value of the number of time_wait sockets allowed by the operating system. If it exceeds With this number, the time_wait socket will be cleared immediately and a warning message will be printed.

#This parameter defaults to 180000. Too many time_wait sockets will slow down the web server.

net.ipv4.tcp_max_tw_buckets = 5000
Copy after login

#Define the value range of the local port for udp and tcp links.

net.ipv4.ip_local_port_range = 1024 65000
Copy after login

# Defines the minimum value, default value, and maximum value for tcp to accept cache.

net.ipv4.tcp_rmem = 10240 87380 12582912
Copy after login

#Define the minimum value, default value and maximum value of tcp send cache.

net.ipv4.tcp_wmem = 10240 87380 12582912
Copy after login

#When the network card receives data packets faster than the kernel processing speed, there will be a queue to save these data packets. This parameter represents the maximum value of the queue.

net.core.netdev_max_backlog = 8096
Copy after login

#Indicates that the kernel socket accepts the default size of the buffer area.

net.core.rmem_default = 6291456
Copy after login

# indicates the default size of the kernel socket send buffer.

net.core.wmem_default = 6291456
Copy after login

#Indicates that the kernel socket accepts a larger buffer size.

net.core.rmem_max = 12582912
Copy after login

#Indicates the larger size of the kernel socket send buffer.

net.core.wmem_max = 12582912
Copy after login

Note: The above four configurations need to be comprehensively considered based on business logic and actual hardware costs;

# has nothing to do with performance. Used to solve tcp syn***.

net.ipv4.tcp_syncookies = 1
Copy after login

#This parameter indicates the maximum length of the syn request queue accepted during the TCP three-way handshake establishment phase. The default is 1024. Setting it larger can prevent Linux from being too busy to accept new connections when nginx is busy. Lost client-initiated link request.

net.ipv4.tcp_max_syn_backlog = 8192
Copy after login

#This parameter is used to set and enable timewait fast recycling.

net.ipv4.tcp_tw_recycle = 1
Copy after login

The default value of the option is 128. This parameter is used to adjust the number of TCP connections initiated by the system at the same time. In high-concurrency requests, the default value may cause the link to time out or retransmit, so it needs to be combined with high concurrency. Adjust this value based on the number of requests. The

net.core.somaxconn=262114
Copy after login

# option is used to set the maximum number of tcp sockets in the system that are not associated with any user file handle. If this number is exceeded, the orphan link will be reset immediately and a warning message will be output. This limit indicates that in order to prevent simple dos***, you do not need to rely too much on this limit or even reduce this value. In more cases, increase this value.

net.ipv4.tcp_max_orphans=262114
Copy after login

For ease of use, you can copy it directly below

net.ipv4.tcp_tw_reuse = 1
fs.file-max = 999999
net.ipv4.tcp_fin_timeout = 30
ner.ipv4.tcp_keepalive_time = 600
Copy after login

The above is the detailed content of How to optimize Nginx high concurrency kernel. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to check whether nginx is started? How to check whether nginx is started? Apr 14, 2025 pm 12:48 PM

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

How to start nginx in Linux How to start nginx in Linux Apr 14, 2025 pm 12:51 PM

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to create a mirror in docker How to create a mirror in docker Apr 15, 2025 am 11:27 AM

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

How to solve nginx403 How to solve nginx403 Apr 14, 2025 am 10:33 AM

How to fix Nginx 403 Forbidden error? Check file or directory permissions; 2. Check .htaccess file; 3. Check Nginx configuration file; 4. Restart Nginx. Other possible causes include firewall rules, SELinux settings, or application issues.

See all articles