Is the fsync() fake on FreeBSD6.1?

Ivan Voras ivoras at fer.hr
Tue Jun 27 23:04:06 UTC 2006


Leo Huang wrote:

> The result is followed:
> OS           Clients        Result(queries per second)  TPS(got from 
> iostat)
> FreeBSD6.1    50               516.1                         about 2000
> Debian3.1     50               49.8                          about 200
> 

> I know that MySQL uses fsync() to flush both the data and log files at

I tried to see the effects from fsync() with this little program:

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

#define BUF_SIZE 512
#define COUNT 50000

int main() {
     int fd;
     char buf[BUF_SIZE];
     int i;

     fd = open("test.file", O_CREAT|O_TRUNC|O_WRONLY, 0600);
     if (fd < 0) {
         printf("cannot open\n");
         exit(1);
     }

     for (i = 0; i < COUNT; i++) {
         if (write(fd, buf, BUF_SIZE) != BUF_SIZE) {
             printf("error writing\n");
             exit(1);
         }
         if (fsync(fd) < 0) {
             printf("error in fsync\n");
             exit(1);
         }
     }

     close(fd);
     unlink("test.file");

     return 0;

But I see strange results with iostat. It shows 16KB transactions, ~2900 
tps and 46 MB/s. On the other hand, the program runs for ~36 seconds, 
which gives ~1390 tps (this is a single desktop drive). Since 36 seconds 
of 46MB/s would result in a file 1.6 GB in size, while it's clearly 
50000*512=25MB, iostat is lying.

I think it's a too valuable tool to be lying. For what it's worth, gstat 
is also lying in the same way.


More information about the freebsd-fs mailing list