系统优化-IO-IO问题导致的接口延迟过高

案例准备:启动一个web应用,用另一个中端请求,发现响应极慢

1
docker run --name=app -p 10000:80 -itd feisky/word-pop
1
curl http://192.168.0.10:1000/popularity/word

top、iostat发现磁盘的io很高,用strace的套路查看代码发现没有write的痕迹,这时候我们可以用bcc-tools下的filetop查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 切换到工具目录
$ cd /usr/share/bcc/tools

# -C 选项表示输出新内容时不清空屏幕
$ ./filetop -C

TID COMM READS WRITES R_Kb W_Kb T FILE
514 python 0 1 0 2832 R 669.txt
514 python 0 1 0 2490 R 667.txt
514 python 0 1 0 2685 R 671.txt
514 python 0 1 0 2392 R 670.txt
514 python 0 1 0 2050 R 672.txt

...

TID COMM READS WRITES R_Kb W_Kb T FILE
514 python 2 0 5957 0 R 651.txt
514 python 2 0 5371 0 R 112.txt
514 python 2 0 4785 0 R 861.txt
514 python 2 0 4736 0 R 213.txt
514 python 2 0 4443 0 R 45.txt

我们可以看到 线程ID,命令,读/写的次数、大小,文件类型,文件名称找到了创建了xxx.txt文件,我们通过ps找到tid所属的进程

1
ps efT|grep 514

在通过bcc下的opensnoop找到具体的文件

1
2
3
4
$ opensnoop
12280 python 6 0 /tmp/9046db9e-fe25-11e8-b13f-0242ac110002/650.txt
12280 python 6 0 /tmp/9046db9e-fe25-11e8-b13f-0242ac110002/651.txt
12280 python 6 0 /tmp/9046db9e-fe25-11e8-b13f-0242ac110002/652.txt

猜测是程序接到请求后,创建了一堆临时文件,在读取到内存,然后删除了文件导致的,修改程序问题解决。