liunx调优实践--没有源码的情况下尽量找出瓶颈点

cpu常见性能指标:

使用率、平均负载、上下文切换

一、CPU调优实践

实践一:用户CPU使用率较高、找到原因并找到代码瓶颈点

 实践一的环境搭建:

$ cat /tftpboot/test.sh

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

 实践二:软中断si--cpu使用率较高、找到代码瓶颈点

网络原因可用另外的工具双重验证--查看收发包频率

nethogs

 实践二的环境搭建:

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

实践三:找出CPU使用较高的原因---io压力层面

 环境搭建:

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;
}

cpu调优常见方法:

 二、内存调优实践

伙伴算法:物理内存的管理职能在cpu内核态进行管理、而不是应用态、4096(4kb)字节一个块、分成四个块

slab管理内存:小内存管理

一个进程所使用的内存可通过PSS和RSS来衡量。

计算进程的Pss:
$ cat /proc/1/smaps | grep Pss | awk '{total+=$2}; END {print total}'

猜你喜欢

转载自blog.csdn.net/weixin_42435798/article/details/126568532
今日推荐