27 | 案例篇:为什么我的磁盘I/O延迟很高?
案例准备
- 机器配置:2 CPU,8GB 内存
- 预先安装 docker、sysstat 等工具,如 apt install docker.io sysstat
案例分析
docker run --name=app -p 10000:80 -itd feisky/word-pop
curl http://192.168.0.10:10000/
hello world
curl http://192.168.0.10:1000/popularity/word
df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 4073376 0 4073376 0% /dev
tmpfs 816932 1188 815744 1% /run
/dev/sda1 30308240 8713640 21578216 29% /
while true; do time curl http://192.168.0.10:10000/popularity/word; sleep 1; done
top
top - 14:27:02 up 10:30, 1 user, load average: 1.82, 1.26, 0.76
Tasks: 129 total, 1 running, 74 sleeping, 0 stopped, 0 zombie
%Cpu0 : 3.5 us, 2.1 sy, 0.0 ni, 0.0 id, 94.4 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu1 : 2.4 us, 0.7 sy, 0.0 ni, 70.4 id, 26.5 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 8169300 total, 3323248 free, 436748 used, 4409304 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 7412556 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12280 root 20 0 103304 28824 7276 S 14.0 0.4 0:08.77 python 16 root 20 0 0 0 0 S 0.3 0.0 0:09.22 ksoftirqd/1
1549 root 20 0 236712 24480 9864 S 0.3 0.3 3:31.38 python3
ps aux | grep app.py
root 12222 0.4 0.2 96064 23452 pts/0 Ss+ 14:37 0:00 python /app.py
root 12280 13.9 0.3 102424 27904 pts/0 Sl+ 14:37 0:09 /usr/local/bin/python /app.py
iostat
- -d 选项是指显示出 I/O 的性能指标;
- -x 选项是指显示出扩展统计信息(即显示所有 I/O 指标)。
iostat -d -x 1
Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util
loop0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda 0.00 71.00 0.00 32912.00 0.00 0.00 0.00 0.00 0.00 18118.31 241.89 0.00 463.55 13.86 98.40
pidstat -d 1
14:39:14 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command
14:39:15 0 12280 0.00 335716.00 0.00 0 python
strace -p 12280
strace: Process 12280 attached
select(0, NULL, NULL, NULL, {tv_sec=0, tv_usec=567708}) = 0 (Timeout)
stat("/usr/local/lib/python3.7/importlib/_bootstrap.py", {st_mode=S_IFREG|0644, st_size=39278, ...}) = 0
stat("/usr/local/lib/python3.7/importlib/_bootstrap.py", {st_mode=S_IFREG|0644, st_size=39278, ...}) = 0
strace -p 12280 2>&1 | grep write
filetop
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
echo "deb https://repo.iovisor.org/apt/$(lsb_release -cs) $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/iovisor.list
sudo apt-get update
sudo apt-get install bcc-tools libbcc-examples linux-headers-$(uname -r)
# 切换到工具目录
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
ps -efT | grep 514
root 12280 514 14626 33 14:47 pts/0 00:00:05 /usr/local/bin/python /app.py
opensnoop
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
ls /tmp/9046db9e-fe25-11e8-b13f-0242ac110002 | wc -l
ls: cannot access '/tmp/9046db9e-fe25-11e8-b13f-0242ac110002': No such file or directory
0
opensnoop
12280 python 6 0 /tmp/defee970-fe25-11e8-b13f-0242ac110002/261.txt
12280 python 6 0 /tmp/defee970-fe25-11e8-b13f-0242ac110002/840.txt
12280 python 6 0 /tmp/defee970-fe25-11e8-b13f-0242ac110002/136.txt
@app.route("/popularity/<word>")
def word_popularity(word): dir_path = '/tmp/{}'.format(uuid.uuid1()) count = 0 sample_size = 1000 def save_to_file(file_name, content): with open(file_name, 'w') as f: f.write(content) try: # initial directory firstly os.mkdir(dir_path) # save article to files for i in range(sample_size): file_name = '{}/{}.txt'.format(dir_path, i) article = generate_article() save_to_file(file_name, article) # count word popularity for root, dirs, files in os.walk(dir_path): for file_name in files: with open('{}/{}'.format(dir_path, file_name)) as f: if validate(word, f.read()): count += 1 finally: # clean files shutil.rmtree(dir_path, ignore_errors=True) return jsonify({'popularity': count / sample_size * 100, 'word': word})
time curl http://192.168.0.10:10000/popularity/word
{ "popularity": 0.0, "word": "word"
}
real 2m43.172s
user 0m0.004s
sys 0m0.007s
time curl http://192.168.0.10:10000/popular/word
{"popularity": 0.0,"word": "word"
}real 0m8.810s
user 0m0.010s
sys 0m0.000s
小结
27 | 案例篇:为什么我的磁盘I/O延迟很高?相关推荐
- 这篇 LaTeX 简单介绍的文章艺术含量很高哒!
目录 一. 工欲利其事,必先利其器 二. 言语互不相通,论文无法完工 三. 标题写起来 ! 四. 报告不能没有目录,就像西方不能没有耶路撒冷 五. 图片 - 文章的灵魂 六. 可不敢抄袭啊,参考文献 ...
- Linux 查看磁盘IO并找出占用IO读写很高的进程
根据磁盘IO告警,找到占用磁盘IO (util)读写很高的进程. 背景-线上告警 线上一台服务器告警,磁盘利用率 disk.util > 90,并持续告警. 登录该服务器后通过 iostat - ...
- mysql(基础案例篇)
mysql(基础案例篇) 1.CRUD1 (创建Create.检索Retrieve.更改Update.删除Delete) 查:select * from 表名 where 条件 删:delect fr ...
- Shader案例篇二《镜子2》
Shader案例篇二<镜子2> 二.Unity中制作原理 1.简单说明:其实这个原理就是用一个摄像机去拍镜子上面的物体将得到的图像投影给Plane,最后主摄像机就能看到Plane上物体的镜 ...
- mysql实例和数据的安全_数据库安全--案例篇
目的 由于<数据库安全浅析>一文中,主要介绍了数据库安全方面的一些基本安全策略,缺少了必要的案例分析和处理过程.为了进一步丰富数据库安全的内容,特撰文案例篇,主要介绍数据库安全上遇到的案例 ...
- asp.net多图片上传案例_会计小明的故事-成本核算案例篇
因涉及成本核算案例篇,所需要的图表比较多,但是知乎不同于微信可以直接将文档图表复制过来,知乎专栏文章,所有图表必须先截图,然后以图片形式展示.但是成本核算案例图表实在是太多,一一截图,一则影响整体观感 ...
- 08 | 案例篇:系统中出现大量不可中断进程和僵尸进程怎么办?(下)
上一节,我给你讲了 Linux 进程状态的含义,以及不可中断进程和僵尸进程产生的原因,我们先来简单复习下. 使用 ps 或者 top 可以查看进程的状态,这些状态包括运行.空闲.不可中断睡眠.可中断睡 ...
- 42 | 案例篇:如何优化 NAT 性能?(下)
上一节,我们学习了 NAT 的原理,明白了如何在 Linux 中管理 NAT 规则.先来简单复习一下. NAT 技术能够重写 IP 数据包的源 IP 或目的 IP,所以普遍用来解决公网 IP 地址短缺 ...
- 41 | 案例篇:如何优化 NAT 性能?(上)
上一节,探究了网络延迟增大问题的分析方法,并通过一个案例,掌握了如何用 hping3.tcpdump.Wireshark.strace 等工具,来排查和定位问题的根源. 简单回顾一下,网络延迟是最核心 ...
最新文章
- Reactor实例解析
- a=a+b与a+=b有什么区别吗?
- 朴素贝叶斯Naïve Bayes分类算法在Hadoop上的实现
- 你所需要的java基础篇和提升篇大总结
- 集成CCFlow工作流与GPM的办公系统驰骋CCOA介绍(二)
- 说白了 枚举是一个对象中属性的参数值
- 零基础学sql要多久_零基础如何学习游戏3D建模,要学些什么内容?学多久?
- tcp 裸流 发送 html,ffmpeg 命令学习
- java 解析xml saxreader_Java中使用DOM和SAX解析XML文件的方法示例
- vue-pdf安装之后,运行报错can not resolve ‘pdfjs-dist/es5/web/pdf_viewer‘
- azw3怎么在Mac电脑上打开?
- LeetCode347. 前 K 个高频元素(含详细解析JAVA实现)
- Mac python 安装信息安全,Pycrypto 出现,C compiler cannot create executablesC编辑器不能创建可执行文件
- [洛谷P3939]数颜色
- 第一个安卓应用小程序--浅浅仿照微信发现界面
- 图形学基础之透视校正插值
- SendMessage函数完全使用手册 (解读WM_)
- 怎么看Mac电脑的序列号,Mac序列号是多少
- winform做的单机登录界面和账号注册界面
- 【思维导图训练1】--思维导图的基本概述
热门文章
- python综合管理系统_学生综合信息管理系统
- integer加1_利用Abaqus UEL开发自定义单元1
- python实现数据库事务回滚_使用Python脚本实现MySQL误操作的快速回滚
- apache相对路径 php,php简单实现相对路径转绝对路径-PHP问题
- php+数学计算公式,PHP数学计算函数总结
- ci mysql操作_CI框架数据库各类操作
- javascript控制html高,Javascript可以控制css吗?
- java system_java System类
- 分享几段祖传的Python代码,拿来直接使用!
- 人脸识别的时候,一定要穿上衣服!否则 ...