In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to set the number of Nginx server processes and the method of using multicore CPU". In daily operation, I believe many people have doubts about how to set up the number of Nginx server processes and how to use multicore CPU. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to set the number of Nginx server processes and how to use multicore CPU". Next, please follow the editor to study!
Nginx profile nginx.conf
First of all, you need to find the configuration file nginx.conf of nginx to do the following. Under the default configuration of the lnmp one-click installation package, nginx.conf is stored in the
/ usr/local/nginx/conf/nginx.conf
As for installing nginx in other environments, you can use
Find /-name nginx.conf
To find the path where the configuration file is stored.
Number of nginx worker_processes processes settin
In nginx's configuration document nginx.conf, you can set worker_processes to change the number of processes in nginx. According to this Q & A number of nginx worker processes, it is recommended that the number of nginx worker_processes processes be set to 1, because:
But our goal is to assign different worker_processes processes to run on different cores, so take the 512 configuration of my current vps provider linode as an example, the server hen has eight logical cpu, but as a user I only get four logical cpu, so here I am set to run three worker_processes processes, because by default, other programs will run on the first logical cpu (cpu0). In order not to affect other programs, I will assign these three processes to run on the other three logical cpu (cpu1, cpu2, cpu3):
Worker_processes 3
Generally speaking, if you have a few logical cpu, it is appropriate to set it to a few worker_processes, but it doesn't make much sense if you have more than 8 worker_processes. The reason has already been mentioned in the above paragraph.
You can use this command to view the current cpu situation:
Cat / proc/cpuinfo
Or directly display the number of logical cpu:
Cat / proc/cpuinfo | grep "processor" | wc-l
Nginx worker_cpu_affinity Settin
According to the data on nginx wiki:
Worker_cpu_affinity is not enabled by default. According to the example, we can see that 0001 0010 0100 1000 represents the 1st, 2nd, 3rd and 4th logical cpu respectively, so we can set 0010 0100 1000 to bind the three processes to the 2nd, 3rd and 4th logical cpu respectively:
Worker_processes 3 workerplate CPUs 0010 0100 1000
At the same time, according to the example, we can see that worker_cpu_affinity can bind the same process to two logical cpu:
Worker_processes 2 workerplate CPUs 0101 1010
0101 on the 1st and 3rd logical cpu, 1010 is on the 2nd and 4th logical cpu.
Enabling and testing of nginx process allocation to multicore cpu settings
Save the nginx.conf file and reload the nginx configuration file:
/ usr/local/nginx/sbin/nginx-s reload
Run ab on another host with apache installed to test:
Ab-n 20000-k http://www.1990y.com/p.php
You can test a php page that requires a mysql query, or you can test a static image or page.
On the server under test, you can use top to view the current server situation, and then press 1 to display the usage of each logical cpu.
Turn on cpu multi-core utilization
Rule setting
(1) there are several digits of the number of cores in cpu. 1 indicates that the kernel is on, and 0 indicates that the kernel is closed.
(2) when a maximum of 8 worker_processes is enabled, the performance of more than 8 will not be improved, and the stability will become lower, so 8 processes are sufficient.
Demo example
Start two processes with two cores of cpu
Worker_processes 2; worker_cpu_affinity 01 10
01 indicates that the first cpu kernel is enabled, and 10 indicates that the second cpu kernel is enabled
Worker_cpu_affinity 01 10; indicates that two processes are started, the first process corresponds to the first cpu kernel and the second process corresponds to the second cpu kernel
Start eight processes with two cores of cpu
Worker_processes 8; worker_cpu_affinity 01 10 01 10 01 10 01 10
Eight processes are started, each of which corresponds to opening two kernels
8-core cpu, start 8 processes
Worker_processes 8; worker_cpu_affinity 10000000 01000000 00100000 00010000 00001000 0000010000001000000001
00000001 means that the first cpu kernel is enabled, 00000010 means that the second cpu kernel is enabled, and so on
8-core cpu, start 2 processes
Worker_processes 2; worker_cpu_affinity 10101010 01010101
10101010 means the kernel 2, 4, 4, 6, and 8 is enabled, and 01010101 means that the kernel 1, 3, 5, and 7 is started.
2 processes correspond to 8 cores
Restart nginx
After the configuration is complete, you need to restart the nginx service
/ etc/init.d/nginx restart at this point, the study on "how to set up the number of Nginx server processes and how to use multicore CPU" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.