Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid caching effects in read benchmarks

I have a read benchmark and between consecutive runs, I have to make sure that the data does not reside in memory to avoid effects seen due to caching. So far what I used to do is: run a program that writes a large file between consecutive runs of the read benchmark. Something like

./read_benchmark
./write --size 64G --path /tmp/test.out
./read_benchmark

The write program simply writes an array of size 1G 64 times to file. Since the size of the main memory is 64G, I write a file that is approx. the same size. The problem is that writing takes a long time and I was wondering if there are better ways to do this, i.e. avoid effects seen when data is cached.

Also, what happens if I write data to /dev/null?

./write --size 64G --path /dev/null

This way, the write program exits very fast, no I/O is actually performed, but I am not sure if it overwrites 64G of main memory, which is what I ultimately want.

Your input is greatly appreciated.

like image 739
jitihsk Avatar asked Dec 12 '22 09:12

jitihsk


2 Answers

You can drop all caches using a special file in /proc like this:

echo 3 > /proc/sys/vm/drop_caches

That should make sure cache does not affect the benchmark.

like image 59
Lukáš Lalinský Avatar answered Dec 28 '22 23:12

Lukáš Lalinský


You can just unmount the filesystem and mount it back. Unmounting flushes and drops the cache for the filesystem.

like image 35
Maxim Egorushkin Avatar answered Dec 29 '22 00:12

Maxim Egorushkin