Home  >  Article  >  Operation and Maintenance  >  What are the main aspects of nginx tuning?

What are the main aspects of nginx tuning?

(*-*)浩
(*-*)浩Original
2019-11-02 09:48:525767browse

What are the main aspects of nginx tuning?

Optimize the maximum number of connections allowed by a single Nginx process (Recommended learning: nginx tutorial)

Control a single Nginx process The parameter for the maximum number of connections allowed is worker_connections. This parameter should be adjusted based on server performance and memory usage.

The maximum number of connections for a process is limited by the maximum number of files opened by the Linux system process. Worker_connections can only take effect after "ulimit -HSn 65535" is executed.

The number of connections includes proxy server connections, client connections, etc. The total number of Nginx concurrent connections = worker_processes * worker_connections. The total number can be kept around 3w.

worker_processes  2;
worker_cpu_affinity 01 10;
user nginx nginx;
events {
    use epoll;
    worker_connections  15000;
}

Bind Nginx processes to different CPUs

By default, multiple Nginx processes may run on a certain CPU or a certain core of the CPU As a result, the Nginx process uses hardware resources unevenly. Therefore, binding the Nginx process to different CPUs is to make full use of the multi-CPU and multi-core resources of the hardware.

[root@localhost ~]# grep -c processor /proc/cpuinfo    # 查看CPU核数
2
worker_processes  2;         # 2核CPU的配置
worker_cpu_affinity 01 10;
 
worker_processes  4;         # 4核CPU的配置
worker_cpu_affinity 0001 0010 0100 1000;   
 
worker_processes  8;         # 8核CPU的配置
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 1000000;
 
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

Optimize the maximum number of connections allowed by a single process of Nginx

The parameter that controls the maximum number of connections allowed by a single process of Nginx is worker_connections. This parameter should be based on server performance and memory. Adjust the usage amount.

The maximum number of connections for a process is limited by the maximum number of files opened by the Linux system process. Worker_connections can only take effect after "ulimit -HSn 65535" is executed.

The number of connections includes proxy server connections, client connections, etc. The total number of Nginx concurrent connections = worker_processes * worker_connections. The total number can be kept around 3w.

worker_processes  2;
worker_cpu_affinity 01 10;
user nginx nginx;
events {
    use epoll;
    worker_connections  15000;
}

The above is the detailed content of What are the main aspects of nginx tuning?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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