Liunx tuning practice -- try to find the bottleneck point without source code

CPU common performance indicators:

Utilization, load average, context switching

1. CPU tuning practice

Practice 1: The user's CPU usage is high, find the reason and find the bottleneck point of the code

 Practice 1 environment construction:

$ cat /tftpboot/test.sh

!/bin/bash
stress --cpu 1 --timeout 12000

 Practice 2: Soft interrupt si--cpu usage is high, find code bottlenecks

The network reason can be double verified by another tool -- check the frequency of sending and receiving packets

nethogs

 Environment construction for practice 2:

host A(本机):
iperf -s -p 10000
host B:
iperf -c 172.21.92.104 -p 10000 -t 10000

Practice 3: Find out the cause of high CPU usage---io pressure level

 Environment construction:

vi test.c

include
include
include
include
include
int main()
{
printf("pid=%d\n", getpid());
char *p = "0123456789\n";
while(1) {
int fd, len;
fd = open("./test.txt", ORDWR|OCREAT|O_APPEND);
if(fd == -1) {
perror("open");
return -1;
}
write(fd, p, strlen(p));
fsync(fd);
close(fd);
}
return 0;
}

Common methods of cpu tuning:

 2. Memory tuning practice

Partner algorithm: The management function of physical memory is managed in the CPU kernel state, not the application state, 4096 (4kb) bytes per block, divided into four blocks

slab management memory: small memory management

The memory used by a process can be measured by PSS and RSS.

Calculate Pss of a process:
$ cat /proc/1/smaps | grep Pss | awk '{total+=$2}; END {print total}'

Guess you like

Origin blog.csdn.net/weixin_42435798/article/details/126568532