使用pt-ioprofile监控数据库io文件读写情况
我们在做IO密集型的应用程序的时候,比如MySQL数据库,通常系统的表现取决于workload的类型。 比如我们要调优,我们就必须非常清楚的知道数据的访问规律,收集到足够的数据,用来做调优的依据。
有很多工具可以收集系统层面的,设备层面的,进程层面的IO数据,但是没有一个现成的工具可以回答我们比如应用打开了多少文件,文件的读和写的比例是多少,调用了多少次sync, 每次的数据大小是多少,调用了多少次,每次用了多少时间, 是顺序操作还是随机操作,是那个线程发起的操作。
pt-ioprofile是percona提供的用于监控进程io和文件读写的一个工具。
pt-ioprofile does two things: 1) get lsof+strace for -s seconds, 2) aggregate the result. If you specify a FILE, then step 1) is not performed.
风险:
WARNING: pt-ioprofile freezes the server and may crash the process, or make it perform badly after detaching, or leave it in a sleeping state! Before using this tool, please:
- Read the tool’s documentation
- Review the tool’s known “BUGS”
- Test the tool on a non-production server
- Backup your production server and verify the backups
pt-ioprofile should be considered an intrusive tool, and should not be used on production servers unless you understand and accept the risks.
由于pt-ioprofile是一种侵入性工具,所以尽量不要在生产上使用,可能会引起进程挂掉。
pt-ioprofile使用的是strace 和lsof来监控进程操作,最后得出操作文件的列表,默认直接运行是监控mysql进程,默认时间是30s。不过也可以用来监控PostgreSQL的服务进程。
下面是几个示例:
使用pgbench进行压测,压测脚本为:
\set id random(,)
insert into test (id,info,crt_time) values (:id, md5(random()::text), now()) on conflict (id) do update
set info=excluded.info, crt_time=excluded.crt_time;
压测命令:
pgbench -M prepared -U swrd swrd -n -r -P -f ./test.sql -c -j -T
指定监控pg进程:
# pt-ioprofile -p 7269
Mon Oct :: CST
Tracing process ID
total read write open close lseek filename
0.078474 0.075984 0.000000 0.001795 0.000000 0.000695 base//2619_fsm
0.049367 0.049318 0.000000 0.000023 0.000000 0.000026 base//
0.004804 0.004764 0.000000 0.000018 0.000011 0.000011 base//
0.003581 0.003302 0.000000 0.000125 0.000154 0.000000 base//pg_internal.init
0.003091 0.000000 0.000000 0.003078 0.000000 0.000013 base//
0.002482 0.000000 0.000000 0.000018 0.000000 0.002464 base//
0.000829 0.000800 0.000000 0.000016 0.000013 0.000000 base//pg_internal.init
0.000770 0.000000 0.000000 0.000042 0.000697 0.000031 base//
0.000613 0.000000 0.000000 0.000181 0.000419 0.000013 base//
0.000567 0.000160 0.000000 0.000301 0.000106 0.000000 pg_stat_tmp/global.stat
0.000448 0.000153 0.000000 0.000154 0.000000 0.000141 base//
0.000385 0.000326 0.000000 0.000035 0.000024 0.000000 global/pg_internal.init
0.000329 0.000190 0.000000 0.000117 0.000022 0.000000 global/pg_filenode.map
0.000253 0.000031 0.000028 0.000114 0.000036 0.000044 base//38453_vm
0.000245 0.000100 0.000000 0.000057 0.000000 0.000088 base//2840_fsm
0.000194 0.000111 0.000000 0.000044 0.000000 0.000039 base//
0.000164 0.000081 0.000000 0.000050 0.000033 0.000000 pg_stat_tmp/db_0.stat
0.000161 0.000107 0.000000 0.000031 0.000023 0.000000 pg_stat_tmp/db_16401.stat
0.000156 0.000000 0.000000 0.000117 0.000000 0.000039 base//2619_vm
0.000150 0.000000 0.000000 0.000064 0.000046 0.000040 base//38453_fsm
0.000101 0.000011 0.000000 0.000071 0.000019 0.000000 base//pg_filenode.map
0.000088 0.000037 0.000000 0.000025 0.000000 0.000026 base//2840_vm
0.000085 0.000000 0.000000 0.000022 0.000012 0.000051 base//
0.000075 0.000000 0.000000 0.000017 0.000011 0.000047 base//
0.000074 0.000045 0.000000 0.000016 0.000013 0.000000 pg_stat_tmp/db_13269.stat
0.000071 0.000000 0.000000 0.000036 0.000013 0.000022 global/
0.000058 0.000021 0.000000 0.000025 0.000012 0.000000 base//PG_VERSION
0.000046 0.000016 0.000000 0.000019 0.000011 0.000000 base//PG_VERSION
0.000039 0.000012 0.000000 0.000016 0.000011 0.000000 base//pg_filenode.map
0.000022 0.000000 0.000000 0.000022 0.000000 0.000000 base//38459_fsm
其中,
read:从文件中读出数据。要读取的文件用文件描述符标识,数据读入一个事先定义好的缓冲区。
write:把缓冲区的数据写入文件中。
pread:由于lseek和read调用之间,内核可能会临时挂起进程,所以对同步问题造成了问题,调用pread相当于顺序调用了lseek和read,这两个操作相当于一个捆绑的原子操作。
pwrite:由于lseek和write调用之间,内核可能会临时挂起进程,所以对同步问题造成了问题,调用pwrite相当于顺序调用了lseek 和write,这两个操作相当于一个捆绑的原子操作。
fsync:确保文件所有已修改的内容已经正确同步到硬盘上,该调用会阻塞等待直到设备报告IO完成。
open:打开一个文件,并返回这个文件的描述符。
close:close系统调用用于“关闭”一个文件,close调用终止一个文件描述符以及文件之间的关联。文件描述符被释放,并能够重新使用。
lseek:对文件描述符指定文件的读写指针进行设置,也就是说,它可以设置文件的下一个读写位置。
fcntl:针对(文件)描述符提供控制。
看看各参数的作用:
--aggregate
统计的方式,默认是sum,也可指定为avg。
short form: -a; type: string; default: sum The aggregate function, either sum or avg. If sum, then each cell will contain the sum of the values in it. If avg, then each cell will contain the average of the values in it.
--cell
显示的单位,默认是times,即IO操作的时间,也可指定为count(IO操作的次数),size(IO操作的大小)
如下所示:
--cell=times
Tracing process ID
total read open close lseek filename
0.000378 0.000351 0.000016 0.000011 0.000000 base//pg_internal.init
0.000140 0.000053 0.000053 0.000034 0.000000 pg_stat_tmp/global.stat
0.000105 0.000077 0.000016 0.000012 0.000000 global/pg_internal.init
0.000067 0.000041 0.000015 0.000011 0.000000 pg_stat_tmp/db_13269.stat
0.000061 0.000000 0.000016 0.000000 0.000045 base//
0.000051 0.000013 0.000025 0.000013 0.000000 global/pg_filenode.map
0.000044 0.000016 0.000015 0.000013 0.000000 pg_stat_tmp/db_0.stat
0.000043 0.000016 0.000016 0.000011 0.000000 base//PG_VERSION
0.000036 0.000011 0.000015 0.000010 0.000000 base//pg_filenode.map
0.000030 0.000000 0.000019 0.000000 0.000011 base//
0.000028 0.000000 0.000017 0.000000 0.000011 global/
--cell=sizes
Tracing process ID
total read open close lseek filename
base//
base//
base//
base//
base//pg_internal.init
pg_stat_tmp/db_16401.stat
base//2840_fsm
global/pg_internal.init
global/
base//38453_vm
base//
pg_stat_tmp/global.stat
pg_stat_tmp/db_0.stat
global/pg_filenode.map
base//pg_filenode.map
base//PG_VERSION
--cell=count
Tracing process ID
total read open close lseek filename
base//pg_internal.init
pg_stat_tmp/global.stat
global/pg_internal.init
pg_stat_tmp/db_16401.stat
base//
pg_stat_tmp/db_0.stat
global/pg_filenode.map
base//PG_VERSION
base//pg_filenode.map
global/
base//
short form: -c; type: string; default: times
The cell contents.
Valid values are:
VALUE CELLS CONTAIN
===== =======================
count Count of I/O operations
sizes Sizes of I/O operations
times I/O operation timing
--group-by
分组的单位,默认是filename,即对文件名进行统计,也可指定为all,即对所有操作进行统计,pid,对进程进行统计
short form: -g; type: string; default: filename
The group-by item.
Valid values are:
VALUE GROUPING
===== ======================================
all Summarize into a single line of output
filename One line of output per filename
pid One line of output per process ID
--run-time
执行strace命令的时间,OPT_RUN_TIME就是--run-time指定的值。
--save-samples
将strace和lsof获取的结果保存到指定的文件中
type: string Filename to save samples in; these can be used for later analysis.
参考:
http://www.cnblogs.com/ivictor/p/6013980.html
https://www.percona.com/doc/percona-toolkit/2.2/pt-ioprofile.html#options
使用pt-ioprofile监控数据库io文件读写情况的更多相关文章
- JAVA之IO文件读写
IO概述: IO(Input output)流 作用:IO流用来处理设备之间的数据传输 ...
- python IO 文件读写
IO 由于CPU和内存的速度远远高于外设的速度,所以,在IO编程中,就存在速度严重不匹配的问题. 如要把100M的数据写入磁盘,CPU输出100M的数据只需要0.01秒,可是磁盘要接收这100M数据可 ...
- NIO与普通IO文件读写性能对比
最近在熟悉java的nio功能.nio采用了缓冲区的方式进行文件的读写,这一点更接近于OS执行I/O的方式.写了个新旧I/O复制文件的代码,练练手,顺便验证一下两者读写性能的对比,nio是否真的比普通 ...
- [PY3]——IO——文件读写
文件打开和关闭 # 使用open 打开文件,返回时值是一个 File-like对象 f.open('/test/file') # 使用read读取文件 f.read( ) # 使用close关闭文件 ...
- python学习笔记 IO 文件读写
读写文件是最常见的IO操作.python内置了读写文件的函数. 读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统完成的,现代操作系统不允许普通的程序直接对磁盘进行操作,所以, 读写 ...
- java IO文件读写例子(OutputStream,InputStream,Writer,Reader)
一,File创建文件 File file = new File("D:" + File.separator + "yi.txt"); 代码示例: package ...
- java io 文件读写操作
写: import java.io.*; String filePath= "F:\\test.txt"; FileWriter fwriter = null; fwriter = ...
- IO文件读写
*b表示二进制模式访问,但是对于Linux或者Unix系统来说这个模式没有任何意义,因为他们把所有文件都看做二进制文件,包括文本文件 一.三种方法读取文件 方法1:open f=open(" ...
- 文件读写监控(inotify, systemtap)
一.inotify inotify是内核的一个特性,可以用来监控目录.文件的读写等事件,当监控目标是目录时,inotify除了会监控目录本身,还会监控目录中的文件.inotify的监控功能由 ...
随机推荐
- IDE看代码,挺好
初学编程的时候总是收到各种警告:“刚学习编程千万不要用IDE,否则会有xxxxxx的后果”.现在工作后发现使用IDE可以方便编写和查看代码,对于较大的项目来说有很多代码,代码之间的关系也比较复杂,ID ...
- SQL语句--连接查询
一.连接查询有以下几种 1.内连接查询 select * from t1 inner join t2 on t1.x = t2.x; 返回有关联的行 2.外链接查询 以下写法都省略了 中间的 out ...
- 记录一下自己申请并使用VPS的全过程
在学习REST API的时候,想要阅读一下谷歌爸爸的api design guide,无奈无情被墙,正好在学习云相关的技术,就想到申请一个VPS来用用. 这次我选择的是hostmybytes,原因有两 ...
- JAVA学习笔记--简介几个常见关键字static、final、this、super
一.static static(静态的),可以放在类.方法.字段之前. 通常,当创建类时,就是在描述那个类的外观与行为.除非用 new 创建那个类的对象,否则,实际上并未获得任何对象.执行 new 来 ...
- JAVA学习笔记--组合与继承
JAVA一个很重要的功能就是代码的可复用性,代码复用可以大大提升编程效率.这里主要介绍两种代码复用方式:组合和继承. 一.组合 组合比较直观,只需在新的类中产生现有类的对象,新的类由现有类的对象组成, ...
- 观察者模式——Java实例
一.定义 观察者模式(有时又被称为模型-视图(View)模式.源-收听者(Listener)模式或从属者模式)是软件设计模式的一种.观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个 ...
- 四种方式实现波浪效果(CSS效果)
一)第一种方法 (1)HTML结构 <body> <div class="animate wave"> <div class="w1&quo ...
- Android 对话框(Dialogs)
对话框是提示用户作出决定或输入额外信息的小窗口. 对话框不会填充屏幕,通常用于需要用户采取行动才能继续执行的模式事件. 1.对话框设计 如需了解有关如何设计对话框的信息(包括语言建议),请阅读对话框设 ...
- “Hello World!”团队第五周第五次会议
博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.checkout&push代码 一.会议时间 2017年11月14日 ...
- 针对某一网站的UI进行分析
本周课上教学通过对PM(项目经理)的学习,我了解到PM 对项目所有功能的把握, 特别是有关的UI内容.最差的UI, 体现了团队的组织架构:其次, 体现了产品的内部结构:最好, 体现了用户的自然需求. ...