echo 3 > /proc/sys/vm/drop_cache
free
同过 free 命令可以查看缓存情况
[root@node-1 ~]# free -m
total used free shared buff/cache available
Mem: 1819 558 995 9 264 1109
Swap: 2047 0 2047
其中,buff/cache 就是缓存资源
手动释放内存
/proc 是一个虚拟文件系统,我们可以通过对它的读写操作做为与kernel实体间进行通信的一种手段。也就是说可以通过修改/proc中的文件,来对当前kernel的行为做出调整。那么我们可以通过调整/proc/sys/vm/drop_caches来释放内存。操作如下:
因为这是一个非破坏性的操作,而且脏对象是不可释放的,所以用户应该首先运行
sync
写入这个文件会导致内核从内存中删除干净的缓存、dentries和inode,从而使内存变得空闲。
要释放pagecache,请使用
echo 1 > /proc/sys/vm/drop_caches
要释放dentries和索引节点,请使用
echo 2 > /proc/sys/vm/drop_caches
要释放pagecache、dentries和索引节点,请使用
echo 3 > /proc/sys/vm/drop_caches
参考链接
https://blog.csdn.net/wyzxg/article/details/7279986/
dd
dd命令用于按照指定大小和个数的数据块来复制文件或转换文件。
Linux系统中有一个名为/dev/zero的设备文件,这个文件不会占用系统存储空间,但却可以提供无穷无尽的数据,可以用来作为dd命令的输入文件,生成一个指定大小的文件。/dev/null是一个无底洞输出设备,可以向它输出任何数据。
命令格式
dd [opertation]
参数介绍
参数 | 作用 |
---|---|
if | 输入的文件名称,例:if=/dev/zero |
of | 输出的文件名称,例:of=/dev/null |
bs | 设置每个“块”的大小 |
count | 设置要复制的“块”的个数 |
iflag/oflag |
dd做读写测试时,要加两个参数 iflag=nocache 和 oflag=direct 参数。没有的话dd有时会显示 从内存中传输数据 的结果,速度会不准确。 append 追加模式(仅对输出有意义;隐含了conv=notrunc) direct 使用直接I/O 存取模式 directory 除非是目录,否则 directory 失败 dsync 使用同步I/O 存取模式 sync 与上者类似,但同时也对元数据生效 fullblock 为输入积累完整块(仅iflag) nonblock 使用无阻塞I/O 存取模式 noatime 不更新存取时间 nocache 丢弃缓存数据 noctty 不根据文件指派控制终端 nofollow 不跟随链接文件 |
seek |
seek的作用是跳过输出文件中指定大小的部分 ,这就达到了创建大文件,但是并不实际写入的目的。 |
skip | 跳过输入文件中指定大小的部分。 |
测试用例
磁盘写入速度
time dd if=/dev/zero of=/var/test bs=8k count=100000 oflag=direct
磁盘读取速度
time dd if=/var/test of=/dev/null bs=8k count=100000 iflag=nocache
磁盘读写速度
time dd if=/var/test of=/tmp/test bs=8k count=100000 iflag=nocache
fio
Fio最初的编写目的是为了避免出于性能原因或查找/重现错误而要测试特定工作负载时编写特殊测试用例程序的麻烦。编写这样一个测试应用程序的过程可能很麻烦,尤其是在您必须经常这样做的情况下。因此,我需要一个能够模拟给定I / O工作负载而又无需一次又一次地编写定制的测试用例的工具。
命令格式
fio [options] [job options] <job files>
参数介绍
参数名称 | 参数说明 |
---|---|
-filename | 文件名称,通常为块设备路径 /dev/sdb。使用 filename=/dev/sda:/dev/sdb 来表示多个 job 的不同 filename。 |
-direct | 是否使用directIO,默认为false,direct=1开启。 |
-iodepth | 队列深度。 |
-thread | 线程数 |
-rw/-readwrite | 读写方式。包含 read、write、trim(仅用于Linux块设备和SCSI字符设备)、randread、randwrite、randtrim(仅用于Linux块设备和SCSI字符设备)、rw/readwrite、randrw 和 trimwrite。其中读写百分比默认是50/50。 |
-rwmixread | 读百分比。默认值50. |
-rwmixwrite | 写百分比。如果rwmixread和rwmixwrite都给出了,并且它们的值加起来不等于100%,那么后者将用于覆盖前者。如果要求fio将读或写限制在某个速率,这可能会干扰给定的速率设置。如果是这样,那么分布可能是不均衡的。默认值:50。 |
-ioengine | libaio,rados,rbd |
-bs | 单次 io 块文件大小。ceph 一般设为4k。 |
-bsrange | 数据块大小范围,默认单位 kb。 |
size | 每个线程读写数据量 |
-numjobs | 创建此 job 克隆数量。 |
-runtime | 总运行时长,默认单位为秒 |
-ramp_time |
If set, fio will run the specified workload for this amount of time before logging any performance numbers. Useful for letting performance settle before logging results, thus minimizing the runtime required for stable results. Note that the
is considered lead in time for a job, thus it will increase the total runtime if a special timeout or
is specified. When the unit is omitted, the value is given in seconds. |
-name | job名称,此参数还具有指示新作业开始的特殊用途。如果fio -name=job1 -name=job2,建立了两个任务,共享-name=job1之前的参数。-name之后的就是job2任务独有的参数。 |
以下为engine参数,必须写在指定的ioengine之后 | |
-clustername | rbd,rados参数。ceph集群名称。 |
-rbdname | rbd参数,RBD image名称。 |
-pool | rbd,rados参数。存储池名称。必写。 |
-clientname | rbd,rados参数。指定用户名(不带’ client. ‘。前缀)用于访问Ceph集群。如果指定了clustername,则clientname应该是完整类型。id字符串。如果没有类型。前缀给定后,fio将添加’ client ‘。默认的。 |
-busy_poll | rbd,rados参数。Poll store instead of waiting for completion. Usually this provides better throughput at cost of higher(up to 100%) CPU utilization. |
测试用例
执行如下命令准备测试客户端
1. 创建 image,为避免内核不支持高级特性,指定layering特性
rbd create --size {megabytes} {pool-name}/{image-name} --image-feature layering
2. 通知 kernal
rbd map {pool-name}/{image-name}
3. 格式化块设备
mkfs.ext4 {block_name}
4. 挂载设备
mkdir {file_path}
mount {block_name} {file_path}
5. 查看设备挂载情况
df
4k随机写
fio -filename=/mnt/rbd-demo/fio.img -direct=1 -iodepth=32 -thread -rw=randwrite -ioengine=libaio -bs=4k -size=200m -numjobs=8 -runtime=60 -group_reporting -name=mytest
4k随机读
fio -filename=/mnt/rbd-demo/fio.img -direct=1 -iodepth=32 -thread -rw=randread -ioengine=libaio -bs=4k -size=200m -numjobs=8 -runtime=60 -group_reporting -name=mytest
4k随机读写,70%读
fio -filename=/mnt/rbd-demo/fio.img -direct=1 -iodepth=32 -thread -rw=randrw -rwmixread=70 -ioengine=libaio -bs=4k -size=200m -numjobs=8 -runtime=60 -group_reporting -name=mytest
1M顺序写,吞吐量
fio -filename=/mnt/rbd-demo/fio.img -direct=1 -iodepth=32 -thread -rw=write -ioengine=libaio -bs=1M -size=200m -numjobs=8 -runtime=60 -group_reporting -name=mytest
结果分析
[root@node-1 ~]# fio -filename=/mnt/rbd-demo/fio.img -direct=1 -iodepth=32 -thread -rw=randwrite -ioengine=libaio -bs=4k -size=200m -numjobs=8 -runtime=60 -group_reporting -name=mytest
mytest: (g=0): rw=randwrite, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=32
...
fio-3.7
Starting 8 threads
mytest: Laying out IO file (1 file / 200MiB)
Jobs: 1 (f=1): [_(7),w(1)][91.7%][r=0KiB/s,w=42.9MiB/s][r=0,w=10.0k IOPS][eta 00m:04s]
mytest: (groupid=0, jobs=8): err= 0: pid=2178: Tue Sep 8 09:39:40 2020
write: IOPS=9440, BW=36.9MiB/s (38.7MB/s)(1600MiB/43386msec) #写时 IOPS 和带宽(BW)总览
slat (usec): min=2, max=630832, avg=692.55, stdev=5663.73 #submission latency,“盘需要多久将IO提交到kernel做处理?”
clat (nsec): min=1476, max=1769.0M, avg=23061496.85, stdev=51507870.00 #completion latency,“kernel 执行完 IO 的时间”
lat (usec): min=68, max=1769.0k, avg=23754.76, stdev=52699.12 #总的延时,主要参考指标
clat percentiles (msec): #completion latency
| 1.00th=[ 3], 5.00th=[ 3], 10.00th=[ 8], 20.00th=[ 9],
| 30.00th=[ 10], 40.00th=[ 12], 50.00th=[ 13], 60.00th=[ 16],
| 70.00th=[ 25], 80.00th=[ 31], 90.00th=[ 32], 95.00th=[ 34],
| 99.00th=[ 255], 99.50th=[ 405], 99.90th=[ 701], 99.95th=[ 827],
| 99.99th=[ 995]
bw ( KiB/s): min= 15, max=47324, per=13.75%, avg=5191.44, stdev=4918.35, samples=603
iops : min= 3, max=11831, avg=1297.69, stdev=1229.64, samples=603
lat (usec) : 2=0.01%, 4=0.01%, 50=0.01%, 100=0.01%, 250=0.01%
lat (usec) : 500=0.03%, 750=0.03%, 1000=0.02%
lat (msec) : 2=0.10%, 4=6.43%, 10=23.90%, 20=35.85%, 50=30.69%
lat (msec) : 100=0.93%, 250=0.97%, 500=0.70%, 750=0.25%, 1000=0.07%
cpu : usr=0.25%, sys=10.03%, ctx=357382, majf=0, minf=12
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=99.9%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.1%, 64=0.0%, >=64=0.0%
issued rwts: total=0,409600,0,0 short=0,0,0,0 dropped=0,0,0,0 #发出的 IO 数量
latency : target=0, window=0, percentile=100.00%, depth=32
Run status group 0 (all jobs):
WRITE: bw=36.9MiB/s (38.7MB/s), 36.9MiB/s-36.9MiB/s (38.7MB/s-38.7MB/s), io=1600MiB (1678MB), run=43386-43386msec
Disk stats (read/write):
dm-0: ios=0/410431, merge=0/0, ticks=0/1271401, in_queue=1271380, util=96.49%, aggrios=0/410272, aggrmerge=0/340, aggrticks=0/1212994, aggrin_queue=1212830, aggrutil=96.47%
sda: ios=0/410272, merge=0/340, ticks=0/1212994, in_queue=1212830, util=96.47%
参考链接
https://blog.csdn.net/feilianbb/article/details/50497845
https://blog.csdn.net/MrSate/article/details/53292102
rados bench
rados 的层面对 pool 存储性能的测试。
命令格式
rados bench -p <pool_name> <seconds> <write|seq|rand> [-b block_size] [-t concurrent_operations] [-k /.../ceph.client.admin.keyring] [-c /.../ceph.conf] [--no-cleanup] [--run-name run_name]
参数介绍
参数名称 | 参数说明 |
---|---|
-p | 测试的pool |
second | 测试时间,单位:秒 |
write|seq|rand | 写 |
-b | 块大小,默认为4M。只写数字不加单位,默认单位 k |
-t | 并发数,默认值:16 |
-k | 指定ceph.client.admin.keyring |
-c | 指定ceph.conf |
–no-cleanup | 表示写完成后不删除数据,可以在测试结束使用 rados -p <pool_name> cleanup 删除 |
–run-name | 默认为benchmark_last_metadata。若做多客户端测试,这个值必须自行设置,否则会导致多客户端读失败 |
测试用例
写
rados bench -p rbd 10 write --no-cleanup
顺序读
rados bench -p rbd 10 seq
随机读
rados bench -p rbd 10 rand
参考链接
https://www.cnblogs.com/gaohong/p/5818086.html
rados bench 二三事
rbd bench
针对块设备的存储性能测试,使用前请挂载好块设备。
使用如下命令查看帮助。
rbd help bench
命令格式
rbd bench [--pool <pool>] [--namespace <namespace>] [--image <image>]/[<pool-name>/[<namespace>/]]<image-name> [--io-size <io-size>] [--io-threads <io-threads>] [--io-total <io-total>] [--io-pattern <io-pattern>] [--rw-mix-read <rw-mix-read>] --io-type <io-type> <image-spec>
参数介绍
参数名称 | 参数说明 |
---|---|
-p/–pool | pool 名称 |
–namespace | namespace 名称 |
–image | image 名称[ |
–io-size | 默认4k |
–io-threads | 线程数,默认16 |
–io-total | 数据量总大小,默认1G |
–io-pattern | rand 或者 seq,默认seq |
–rw-mix-read | 读比率,默认(50%读/50%写) |
–io-type | read,write,readwrite(rw) |
测试用例
顺序写
rbd bench ceph-demo/test.img --io-size 1M --io-total 200M --io-pattern seq --io-type write
随机写
rbd bench ceph-demo/test.img --io-size 1M --io-total 200M --io-pattern rand --io-type write
顺序读
rbd bench ceph-demo/test.img --io-size 1M --io-total 200M --io-pattern seq --io-type read
随机读
rbd bench ceph-demo/test.img --io-size 1M --io-total 200M --io-pattern rand --io-type write
参考链接
https://www.cnblogs.com/gaohong/p/5818086.html
iozone
filebench