CPU Tuning
How the CPU processes data:
1: Batch processing, sequential processing requests. (Less switching times, larger throughput)
2: time-sharing processing. (like "exclusive", throughput is small) (Time slices, the request is divided into one piece of time, a piece of the CPU processing) we are using x86 is this architecture
3: Real-time processing.
Batch processing-a system used in a previous mainframe (MAINFRAME) that requires a batch of programs to be written in advance (perforated paper tape) and calculated to produce results
Time-Sharing-now popular PC and server is the use of this mode of operation, that is, the operation of the CPU into a number of time slices to handle different operation requests
Real-time--usually used on SCM, such as elevator up and down control, for the button and other action requirements for real-time processing
Kernel Interrupt
grep hz/boot/config-2.6.32-431.el6.x86_64//is a parameter file for compiling the kernel
Onfig_no_hz=y
# config_hz_100 is not set
# config_hz_250 is not set
# config_hz_300 is not set
config_hz_1000=y
Config_hz=1000 #每一秒中有1000个中断
CONFIG_MACHZ_WDT=m
Interrupt
Interrupts are any unusual or unexpected urgent processing events that occur during the execution of a computer, causing the CPU to temporarily interrupt the currently executing program and then go on to execute the appropriate time handler. When it is finished, it returns to the process of continuing or dispatching a new process to be executed. An interrupt is a process that invokes the appropriate handler when an external event occurs.
Hard Interrupt
The asynchronous signal that the peripheral hardware sends to the CPU or memory is a hard interrupt signal. In short: the interruption of the peripheral to the CPU, as a result of randomness and suddenness, a hardware interrupt handler ensures that it completes its task quickly so that the program executes without waiting for a long time, the interruption caused by an external device (such as a input) request, also known as an external interrupt or I/O interruption. For example (mouse click program "Cancel")
Soft interrupt
The interrupt signal sent by the software itself to the operating system kernel is called a soft interrupt. It is usually the interruption of the operating system kernel by a hard interrupt handler or process scheduler, which is what we often call system calls. The time that the soft interrupt occurs is controlled by the
Why do computers use interrupts
To illustrate this issue, give an example. Suppose you have a friend to visit you, but because you do not know when to arrive, you can only wait at the gate, so nothing can do. If you install a doorbell at the door, you do not have to wait at the door to do other work, the friend rang the bell to inform you, you then interrupted your work to open the door, so as to avoid waiting and wasting time. Computer is the same, such as printing output, the speed of the CPU to transfer data, while the printer printing speed is low, if not the use of interrupt technology, the CPU will often be in a waiting state, very inefficient. And the use of interrupt mode, the CPU can do other work, only in the printer buffer in the current content printing completed after the interruption request, only to be responded to temporarily interrupt the current work to carry out the buffer transfer data, transmission completed and return to the original program. This greatly improves the efficiency of the computer system.
Adjust process priority use more CPUs
Adjust the process nice value to allow the process to use more CPUs
Nice value range,-20 ~ 19 Smaller priority higher average user 0-19
Function: Run the process at what priority. Default priority is 0
syntax: nice-n Priority number command
[root@localhost ~] #nice-N-5 vim a.txt//vim process with-level 5
[Root@localhost ~]# Ps-axu | grep b.txt
Warning: bad Syntax, perhaps a bogus '-'? I/usr/share/doc/procps-3.2.8/FAQ
Root 24318 0. 0 0. 2 143624 3280 pts/4 s+ 0vim b.txt
[Root@localhost ~]# top-p 24318
PID USER PR NI virt RES SHR S%CPU%MEM time+ COMMAND
24219 Root -5 140m3336 2200 S 0. 0 0. 3 0. Vim
Renice Modify the priority of a running process and change the priority of a running process
Renice-n 5 PID//Modify Process Priority
[root@localhost ~] #renice-N 5 24318
[Root@localhost ~]# top-p 24318
PID USER PR NI virt RES SHR S%CPU%MEM time+ COMMAND
24219 Root 5 140m3336 2200 S 0. 0 0. 3 0. Vim
Nice value validation
[root@localhost~]# renice-n-21 24219
24219: old priority -new priority -20
[Root@localhost ~]# renice-n 20 24219
24219: old priority -new priority 19
CPU Affinity
In multi-core cases, you can assume that specifying a process on which CPU executes the program, reducing the cost of the process switching before different CPUs, using the Taskset command
[Root@localhost ~]# rpm-ivh/media/packages/util-linux-ng-2.17.2-12.4.el6.x86_64
Syntax: taskset-c N command//-c=cuplist n= number of CPUs, Cpuinfo #
[Root@localhost ~]# taskset-c 0 vim a.txt//Ben is a 4-core CPU that specifies the VIM command to run on the first CPU, and the number 1th CPU ID is 0
[Root@localhost ~]# Ps-axu | grep vim
Warning: bad Syntax, perhaps a bogus '-'? I/usr/share/doc/procps-3.2.8/FAQ
Root 2614 1. 3 0. 2 143696 3332 pts/0 s+:0 vim a.txt
[Root@localhost ~]# taskset-p 2614//process ID to view
pid2614 ' s current affinity mask:1 #CPU亲和力掩码, 1 represents the first CPU core
Find out which CPUs the sshd process is running on
[Root@localhost ~]# Ps-axu | grep sshd
Warning: bad Syntax, perhaps a bogus '-'? I/usr/share/doc/procps-3.2.8/FAQ
Root 2030 0. 0 0. 0 64068 1140 ? Ss:0 /usr/sbin/sshd
[Root@localhost ~]# Taskset-p 2030
pid2030 ' s current affinity mask:f #说明sshd在4颗CPU上随机进行切换.
About conversion methods
8 Core CPU Id:7 6 5 4 3 2 1 0
decimal digits corresponding to 10:128 64 32 16 8 4 2 1
Hexadecimal 16 numbers are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Corresponds to each of the 16 bits: 0=0000,1=0001,2=0010,3=0011,4=0100,5=0101,6=0110,7=0111,8=1000,9=1001,a=1010,
b=1011,c=1100,d=1101,e=1110,f=1111
So for example, the PID 8987 ' s current affinity mask:ff FF is 16 binary, converted to binary: 11111111, meaning that sshd on 8 CPUs instead. So correspond to each number!
Let's say 16 in 40, then convert binary 01000000, which means it works on the 7th CPU.
[Root@localhost ~]# taskset-c 1,5 vim 1.txt//run on the first CPU and 6 CPUs
[Root@localhost ~]# Ps-aux | grep vim
Warning: bad Syntax, perhaps a bogus '-'? I/usr/share/doc/procps-3.2.8/FAQ
Root 7414 0. 3 0. 2 143528 3940