nginx configuration in detail (a)

1.worker_processes: worker processes, can be seen by the following command worker_processes default number of worker processes is a worker process

General Configuration number of CPU cores must be configured or arranged directly auto

[root @ localhost ~] # CAT /apps/nginx/conf/nginx.conf|grep Work 
worker_processes 1; 
the number of nginx before worker_processes # modify parameters worker process 
[root @ localhost ~] # PS -ef | grep nginx 
root 1162 1 ? 0 00:00 00:00:00 nginx: Master Process / Apps / nginx / sbin / nginx -c /apps/nginx/conf/nginx.conf 
nginx nginx 00:00:00 1225 1162 0 00:19:? worker process 
the root PTS 01:24 1302 1250 0/0 = 00:00:00 grep --color Auto nginx 
[the root @ localhost ~] # 
# the worker process is modified after 2, and a hot start to see the number of worker processes nginx 
[ ~ @ localhost the root] # VI /apps/nginx/conf/nginx.conf 

User Nginx Nginx; 
worker_processes 2; 
 
[the root @ localhost ~] # -t Nginx
Nginx: Configuration File The syntax /apps/nginx/conf/nginx.conf IS OK
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost ~]# nginx -s reload
[root@localhost ~]# ps -ef|grep nginx
root       1162      1  0 00:00 ?        00:00:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
nginx      1306   1162  0 01:26 ?        00:00:00 nginx: worker process
nginx      1307   1162  0 01:26 ?        00:00:00 nginx: worker process
root       1309   1250  0 01:26 pts/0    00:00:00 grep --color=auto nginx
[root@localhost ~]# 

#配置成auto
[root@localhost ~]# ps -ef|grep nginx
root       1162      1  0 00:00 ?        00:00:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
nginx      1306   1162  0 01:26 ?        00:00:00 nginx: worker process
nginx      1307   1162  0 01:26 ?        00:00:00 nginx: worker process
root       1309   1250  0 01:26 pts/0    00:00:00 grep --color=auto nginx
[root@localhost ~]# vi /apps/nginx/conf/nginx.conf
user  nginx nginx;
worker_processes  auto;
[root@localhost ~]# nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost ~]# nginx -s reload
[root@localhost ~]# ps -ef|grep nginx
root       1095      1  0 23:38 ?        00:00:00 nginx: master process nginx
nginx      1103   1095  0 23:40 ?        00:00:00 nginx: worker process
nginx      1104   1095  0 23:40 ?        00:00:00 nginx: worker process
root       1107   1073  0 23:41 pts/0    00:00:00 grep --color=auto nginx

2.nginx of worker_cpu_affinity nginx will bind the work process on the specified CPU core running nginx default will not be binding process

The binding does not mean that the current process nginx exclusive one CPU core, but can guarantee that once the process is not run on other core, which greatly reduced

Less nginx worker processes to jump back and forth on a different CPU core, reducing the CPU to the process of resource allocation and recovery as well as memory management, so you can

Effectively improve the nginx server performance.

[the root @ localhost ~] # VI /apps/nginx/conf/nginx.conf 
User Nginx Nginx; 
worker_processes Auto; 
worker_cpu_affinity 00000001 00000010; 
[the root @ localhost ~] # -t Nginx 
Nginx: The Configuration File / Apps / Nginx / the conf IS the ok syntax /nginx.conf 
nginx: the Configuration File /apps/nginx/conf/nginx.conf the Test IS successful 
[root @ localhost ~] # nginx -s reload 
[root @ localhost ~] # PS AXO pid, cmd, PSR | Nginx grep 
  1095 Nginx: Nginx process Master. 1 
  1113 Nginx: process worker 0 
  1114 Nginx: process worker. 1 
  1116 grep --color Nginx 0 = Auto 
  # current can be seen from the above figure process worker working on a different CPU in

When verification is not bound CPU, whether there will be CPU drift, you first need to download the ab command, using the ab command to simulate the pressure test, then look into

Cheng run on which CPU

[root@localhost ~]# yum -y install httpd-tools		#下载ab命令
[root@localhost ~]# ps axo pid,cmd,psr |grep nginx
  1095 nginx: master process nginx   1
  1124 nginx: worker process         0
  1125 nginx: worker process         1
  1165 grep --color=auto nginx       1
[root@localhost ~]# ab -n1000 -c1000 http://192.168.1.170/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.170 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/1.14.2
Server Hostname:        192.168.1.170
Server Port:            80

Document Path:          /index.html
Document Length:        612 bytes

Concurrency Level:      1000
Time taken for tests:   0.065 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      845000 bytes
HTML transferred:       612000 bytes
Requests per second:    15424.24 [#/sec] (mean)
Time per request:       64.833 [ms] (mean)
Time per request:       0.065 [ms] (mean, across all concurrent requests)
Transfer rate:          12728.01 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   17   5.8     16      27
Processing:     7   15   6.9     11      30
Waiting:        0   14   7.5     11      30
Total:         17   32   5.7     34      38

Percentage of the requests served within a certain time (ms)
  50%     34
  66%     35
  75%     36
  80%     36
  90%     36
  95%     37
  98%     38
  99%     38
 100%     38 (longest request)
[root@localhost ~]# ps axo pid,cmd,psr |grep nginx
  1095 nginx: master process nginx   1
  1124 nginx: worker process         0
  1125 nginx: worker process         0
  1168 grep --color=auto nginx       1 

3, worker_connections: set the maximum number of concurrent nginx worker processes for each of the acceptable, as when the nginx web server

The maximum number of concurrent to worker_connections * worker_processes; as a reverse proxy server or load-balancing server time,

The maximum number of concurrent nginx is (worker_connections * worker_processes) / 2; change the default parameter is 1024; 10 may also be provided

Million connections.

# View the default configuration 
[root @ localhost ~] # CAT /apps/nginx/conf/nginx.conf|grep worker 
worker_processes Auto; 
worker_cpu_affinity 00000001 00000010; 
    worker_connections 1024; # default configuration size 
  
# settings on each worker can process 100,000 concurrent connections 
[the root @ localhost ~] -1 worker_connections /apps/nginx/conf/nginx.conf|grep CAT # 
Events { 
    worker_connections 100000; 
}

  

 

Guess you like

Origin www.cnblogs.com/tester-hqser/p/12105265.html