Using “sysbench” to test memory performance

Sysbench is a powerful testing tool for CPU / Memory / Mysql etc. Three years ago, I used to test performance of MYSQL by using it.
Yesterday, I used Sysbench to test memory bandwidth of my server.
By using command:

This regression of memory performance really confuse me. Maybe the memory of modern machines has some kind of “Max limited frequency” so we can’t access memory with too high frequency?
After checked the code of Sysbench, I found out its logic about memory test is just like this program (I wrote it myself):

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

/* mytest.c */

#include <sys/time.h>

#include <stdio.h>

#include <stdlib.h>

constlongDATA=(100*1024*1048576LL);/* 100G data */

intmain(intargc,char*argv[]){

volatile inttmp=0;

int*buffer,*end,*begin;

longi,loop,block_size;

structtimeval before,after;

if(argc<2){

return-1;

}

block_size=atoi(argv[1]);

buffer=(int*)malloc(block_size);

end=(int*)(((char*)buffer)+block_size);

loop=(long)DATA/block_size;

gettimeofday(&before,NULL);

for(i=0;i<loop;i++){

for(begin=buffer;begin<end;begin++){

*begin=tmp;

}

}

gettimeofday(&after,NULL);

printf("time: %lu\n",(after.tv_sec *1000000+after.tv_usec)

-(before.tv_sec *1000000+before.tv_usec));

free(buffer);

}

But this test program cost only 14 seconds (Sysbench cost 49 seconds). To find out the root cause, we need to use a more powerful tool — perf:

They have totally different CPU cache-misses. The root cause is because Sysbench use a complicate framework to support different test targets (Mysql/Memory …), which need to pass a structure named “request” and many other arguments in and out of execution_request() function many times in one request (accessing 1K memory, in our scenario), this overload becomes big when block size is too small.

The conclusion is: don’t use Sysbench to test memory performance by using too small block size, better bigger than 1MB.

Ref: by Coly Li ‘s teaching, memory do have “top limit access frequency” (link). Take DDR4-1866 for example: it’s data rate is 1866MT/s （MT = Mega Transfer) and every transfer takes 8 bytes, so we can access memory more than 1 billion times per second, theoretically.