> 文档中心 > PSI_压力阻塞信息

PSI_压力阻塞信息

 

1. PSI_压力阻塞信息

1.1 PSI的使用



当CPU、memory或IO设备处于竞争状态,业务负载会遭受时延毛刺、吞吐量降低,及面临OOM的风险。
 
psi能够实时的提供相关信息,因此系统可基于psi实现动态的负载管理。如实施卸载、迁移、策略性的停止或杀死低优先级或可重启的批处理任务。

1.1.1 压力信息查看

# cpu 状态tan@tan:~$ cat /proc/pressure/cpusome avg10=0.10 avg60=0.41 avg300=0.21 total=1135875full avg10=0.00 avg60=0.02 avg300=0.00 total=358411tan@tan:~$#io 状态tan@tan:~$ cat /proc/pressure/iosome avg10=1.70 avg60=10.00 avg300=8.05 total=35190768full avg10=1.70 avg60=9.40 avg300=7.50 total=32714449tan@tan:~$# memory状态tan@tan:~$ cat /proc/pressure/memorysome avg10=0.00 avg60=0.00 avg300=0.00 total=0full avg10=0.00 avg60=0.00 avg300=0.00 total=0tan@tan:~$

some 行代表至少有一个任务阻塞于特定资源的时间占比。
full行代表所有非idle任务同时阻塞于特定资源的时间占比。
avg代表阻塞时间占比(百分比),为最近10秒、60秒、300秒内的均值。
total代表总阻塞时间(单位微秒),可用于观察时延毛刺,这种毛刺可能在均值中无法体现。
 

1.1.2 用户态监视例子

  #include   #include   #include   #include   #include   #include   /* 监控内存部分阻塞,监控时间窗口为1秒、阻塞门限为150毫秒。*/  int main() { const char trig[] = "some 150000 1000000"; struct pollfd fds; int n; fds.fd = open("/proc/pressure/io", O_RDWR | O_NONBLOCK); if (fds.fd < 0) {  printf("/proc/pressure/memory open error: %s\n",   strerror(errno));  return 1; } fds.events = POLLPRI; if (write(fds.fd, trig, strlen(trig) + 1) < 0) {  printf("/proc/pressure/memory write error: %s\n",   strerror(errno));  return 1; } printf("waiting for events...\n"); while (1) {  n = poll(&fds, 1, -1);  if (n < 0) {   printf("poll error: %s\n", strerror(errno));   return 1;  }  if (fds.revents & POLLERR) {   printf("got POLLERR, event source is gone\n");   return 0;  }  if (fds.revents & POLLPRI) {   printf("event triggered!\n");  } else {   printf("unknown event received: 0x%x\n", fds.revents);   return 1;  } } return 0;  }

 
根据 1.1.1 压力信息查看 可以知道占空比最大的是io事件,因此 1.1.2 用户态监视例子 修改为监控io事件。

tan@tan:~/toolLinux$ vim psi.ctan@tan:~/toolLinux$ gcc psi.c  -o psitan@tan:~/toolLinux$ sudo ./psi[sudo] password for tan:waiting for events...event triggered!event triggered!event triggered!

 
根据psi中 io的 avg10=1.70, 10000 *1.7% / 10 = 170ms,170ms 大于150ms,所以 都成功的监听到了事件出发。

更多详细得解读可以参考 2.1 技术参考

2. 总结

进入linux大门可以看哈这个视屏:https://ke.qq.com/course/417774?flowToken=1042383
学习还是得靠自己。❤️

2.1 技术参考

参考链接1:https://blog.csdn.net/shift_wwx/article/details/121537332