惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
IT之家
IT之家
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
爱范儿
爱范儿
博客园 - 聂微东
F
Fortinet All Blogs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
雷峰网
雷峰网
B
Blog RSS Feed
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - New Yang Bo Element

Linux下网络流量实时监控工具 linux 内存清理/释放命令 fstab 中 通过UUID挂载 参数解释 Linux vmstat命令实战详解 iostat命令详解 Replace Pioneer注册 linux 下查看某个端口是否工作的命令 linux 学习总结 20100531 RedHat Linux AS5安装Oracle 10g 及常见问题 Ubuntu9.04下安装Oracle10.2 查看Linux下网卡状态或 是否连接 在 linux 下查看 查看服务器的机器型号和序列号 - New Yang Bo Element Linux操作系统静态路由设置技巧介绍 中宇 设备证书 导入配置 Linux/Unix命令之Ethtool (设置千兆网卡速度及模式) GRUB引导下进Linux单用户模式的三种方式 IE7优化方法 联想网上直销2799元笔记本电脑 朗科发布首款固态硬盘 将引PC更新换代潮
磁盘文件读性能测试
New Yang Bo Element · 2014-04-16 · via 博客园 - New Yang Bo Element

未缓存前:

time ./x bin.tar 

file size is 816322560

816322560 bytes read now

real    0m3.378s

user    0m0.000s

sys     0m0.996s

被缓存后:

time ./x bin.tar 

file size is 816322560

816322560 bytes read now

real    0m0.770s

user    0m0.000s

sys     0m0.768s

硬盘读取性能:

hdparm -t /dev/sdb 

/dev/sdb:

 Timing buffered disk reads: 2454 MB in  3.00 seconds = 817.84 MB/sec

10块物理磁盘,做了Raid10,因此读性能高,达每秒817.84MB

测试程序:

// 非优化方式编译:g++ -g -o x x.cpp

#include <errno.h>

#include <fcntl.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

// 带一个参数,为被读取文件的大小

int main(int argc, char* argv[])

{

        int fd = open(argv[1], O_RDONLY);

        if (-1 == fd)

        {

                perror(strerror(errno));

                exit(1);

        }

        struct stat st;

        if (0 == fstat(fd, &st))

        {

                // 输出文件大小,单位为字节

                printf("file size is %d\n", st.st_size);

                // 一次性将整个文件读到内存中

                char* bytes = new char[st.st_size];

                int bytes_read = read(fd, bytes, st.st_size);

                // 显示实际成功读取的字节数

                printf("%d bytes read now\n", bytes_read);

                delete []bytes;

        }

        close(fd);

        return 0;

}

清缓存:

使用free命令观察下列操作的变化,以root用户执行:先执行下sync命令,以将数据更新到磁盘,再执行echo 3 > /proc/sys/vm/drop_caches,以清除系统的cached

文件内存的缓存会反应出free命令输出的cached值的变化,实际就是Page cache,文件内容的读取会缓存在这里。如果读取一个大文件,可以看到cached的值明显增涨,并且增涨大小差不多就是文件的大小,buffers相当于cached的元信息,比如文件的inode

cached影响文件的读取性能,而buffers影响到文件的打开性能。

drop_caches使用汇总:

echo 0 > /proc/sys/vm/drop_caches

不做释放

echo 1 > /proc/sys/vm/drop_caches

释放Page Cache

echo 2 > /proc/sys/vm/drop_caches

释放Dentries/inodes Cache(其中,Dentry是目录信息,inode是文件信息)

echo 3 > /proc/sys/vm/drop_caches

释放PageDentries/inodes Cache

这个特性由2.6.16内核开始提供,参考资料:

1) /proc/sys/vm/drop_caches

http://linux-mm.org/Drop_Caches

2) Linux Buffer vs Cache explained

http://random-techbits.blogspot.com/2012/06/linux-buffer-vs-cache-explained.html