Set Nginx process to allocate up to core CPU boost performance

Source: Internet
Author: User
Tags mysql query

Nginx configuration file nginx.conf

The first need to find Nginx configuration file nginx.conf in order to do the following, in the LNMP one-click installation package By default configuration, nginx.conf stored in
/usr/local/nginx/conf/nginx.conf
For other environments, the installation of Nginx can be
find / -name nginx.conf
To find the storage path for the configuration file.

Nginx worker_processes Process Number setting

Nginx Configuration document nginx.conf can be set worker_processes to change the number of nginx process, according to this question # of Nginx worker processes display, recommend Nginx Worker_pro The number of cesses processes is set to 1 because:

Nginx Unlike Apache and other process per connection webservers. It uses one master process to start and monitor a small number of workers processes that actually handle the connections. My recommendation is to start with the default number of workers, which is 1.

But our goal is to assign different worker_processes processes to CPUs running on different cores, so with the 512 configuration of my current VPS provider Linode as an example, the server hens have 8 logical CPUs, but as a user I have only 4 logical CPUs, So here I am set to run 3 worker_processes processes, because by default, other programs will run on the 1th logical CPU (CPU0), in order not to affect other programs, I will assign these 3 processes to another 3 logical CPUs (CPU1, CPU2, CPU3) running on:

worker_processes 3;

In general, have a few logical CPUs, set as a few worker_processes is advisable, but worker_processes more than 8 is not much significance, the reasons for the above paragraph in the English has been mentioned.

You can use this command to view the current CPU situation:
cat /proc/cpuinfo
or directly display the number of logical CPUs:
cat /proc/cpuinfo |grep "processor"|wc -l

Nginx worker_cpu_affinity Settings

According to the data on Nginx Wiki:

Worker_cpu_affinity

Syntax:worker_cpu_affinity cpumask [cpumask ...]

Default:none

Linux only.

With this option you can bind the worker process to a CPU, it calls Sched_setaffinity ().

For example,

Worker_processes     4;worker_cpu_affinity 0001 0010 0100 1000;

Bind each worker process to the one CPU only.

Worker_processes     2;worker_cpu_affinity 0101 1010;

Bind the first worker to CPU0/CPU2, bind the second worker to Cpu1/cpu3. This is the suitable for HTT.

Worker_cpu_affinity default is not open, according to the example we can see that 0001 0010 0100 1000 represents the 1th, 2, 3, 4 logical CPUs, so we can set 0010 0100 1000来 bind 3 processes to 2nd, 3 , 4 logical CPUs:
worker_processes 3;
worker_cpu_affinity 0010 0100 1000;

Also, as we can see from the example, worker_cpu_affinity can bind the same 1 processes on 2 logical CPUs:
worker_processes 2;
worker_cpu_affinity 0101 1010;

0101 is the 1th, 3 logical CPUs, 1010 is the 2nd, 4 logical CPUs.

Nginx process assignment to enable and test for up to core CPU settings

Save nginx.conf 文件,并重新加载 Nginx 配置文件:
/usr/local/nginx/sbin/nginx-s Reload

Run AB under another Apache-installed host 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 picture or page.

On the tested server, you can use top to view the current server situation, and then press to display the usage of each logical CPU.

Why do I have to set the Nginx process to allocate up to a core CPU? This is not life is to toss it.

No related posts.

Set Nginx process to allocate up to core CPU boost performance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.