bandwidth教程

本文主要讲述一下内存吞吐量的测试。在开发,特别是压力测试的时候,需要知道测试的瓶颈在哪里(是在内存、网络还是磁盘呢?),所以就需要对内存、网络以及磁盘的真实的吞吐量有一定的了解。本文主要讲述内存顺序随机等读写测试。

Bandwidth[1]是一个内存测试工具。本文主要讲述bandwidth安装以及测试步骤,以及结果查看方式。

1、点击下载[2]之后。解压到目录下。

2、安装nasm以及gcc。yum install nasm; yum install gcc

3、编译:输入make会提示你在不同机器上不同的编译指令。在centos x86_64 上面的命令是: make bandwidth64

备注:第3步有可能出现stropts.h: No such file or directory的错误。解决方法就是此文章[3]说的[
编译程序时,出现了这个错误,因为linux不支持STREAMS,缺少这个文件。stropts.h是POSIX XSR的一部分,但是linux不支持。解决办法很简单,在/usr/include目录下创建一个空的stropts.h文件.]

4、运行:当编译成功后,直接运行./bandwidth64 即可。会产生一个图片文件。你还可以重定向把日志输出到一个日志文件中,以便查看日志。
./bandwidth64 > out.log

5、运行结果查看
run-out
上图可以看出来在三个地方曲线有明显的转折。分别是32k、256K、12MB。这分别是三级缓存的大小。就跟下图所示一样
three-level-cache

也就是说:当读写的size大小落在相应的cache里面的时候,吞吐量是最大的。当读写的大小的size超过这个cache,而落入到下一个cache的时候,吞吐量就会降低。内存是最低的。

名字解释:
non-temporal[4]. 说白了non-temporal就是读写数据不经过cache,而是直接去内存中。所以,反应的能力就是内存的能力,而不是cache的能力。

[备注]non-temporal解释:
Non-Temporal SSE instructions (MOVNTI, MOVNTQ, etc.), don’t follow the normal cache-coherency rules. Therefore non-temporal stores must be followed by an SFENCE instruction in order for their results to be seen by other processors in a timely fashion.

When data is produced and not (immediately) consumed again, the fact that memory store operations read a full cache line first and then modify the cached data is detrimental to performance. This operation pushes data out of the caches which might be needed again in favor of data which will not be used soon. This is especially true for large data structures, like matrices, which are filled and then used later. Before the last element of the matrix is filled the sheer size evicts the first elements, making caching of the writes ineffective.

For this and similar situations, processors provide support for non-temporal write operations. Non-temporal in this context means the data will not be reused soon, so there is no reason to cache it. These non-temporal write operations do not read a cache line and then modify it; instead, the new content is directly written to memory.

参考文献