mirror of
https://github.com/postgres/postgres.git
synced 2025-05-31 03:21:24 +03:00
Have program default to 1000 loops, and add file name and loop option.
Make open/close loop testings the same. Add descriptions for certain tests.
This commit is contained in:
parent
9ae9ad155d
commit
9e231bab65
@ -1,7 +1,5 @@
|
|||||||
This program tests fsync. If first times a simple read. Then, it times
|
This program tests fsync. The tests are described as part of the program output.
|
||||||
an fsync that is part of a write, and one that is done on a newly opened
|
|
||||||
file. Third, it tests various fsync methods.
|
|
||||||
|
|
||||||
The program writes to /var/tmp because /tmp is sometimes a memory file
|
Usage: test_fsync [-f filename] [loops]
|
||||||
system.
|
|
||||||
|
|
||||||
|
Loops defaults to 1000.
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define FSYNC_FILENAME "/var/tmp/test_fsync.out"
|
||||||
|
|
||||||
/* O_SYNC and O_FSYNC are the same */
|
/* O_SYNC and O_FSYNC are the same */
|
||||||
#if defined(O_SYNC)
|
#if defined(O_SYNC)
|
||||||
#define OPEN_SYNC_FLAG O_SYNC
|
#define OPEN_SYNC_FLAG O_SYNC
|
||||||
@ -36,12 +38,25 @@ main(int argc, char *argv[])
|
|||||||
struct timeval start_t;
|
struct timeval start_t;
|
||||||
struct timeval elapse_t;
|
struct timeval elapse_t;
|
||||||
int tmpfile,
|
int tmpfile,
|
||||||
i;
|
i,
|
||||||
|
loops=1000;
|
||||||
char *strout = (char *) malloc(65536);
|
char *strout = (char *) malloc(65536);
|
||||||
|
char *filename = FSYNC_FILENAME;
|
||||||
|
|
||||||
|
if (argc > 2 && strcmp(argv[1],"-f") == 0)
|
||||||
|
{
|
||||||
|
filename = argv[2];
|
||||||
|
argv += 2;
|
||||||
|
argc -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
loops = atoi(argv[1]);
|
||||||
|
|
||||||
for (i = 0; i < 65536; i++)
|
for (i = 0; i < 65536; i++)
|
||||||
strout[i] = 'a';
|
strout[i] = 'a';
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
|
|
||||||
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
write(tmpfile, strout, 65536);
|
write(tmpfile, strout, 65536);
|
||||||
fsync(tmpfile); /* fsync so later fsync's don't have to do
|
fsync(tmpfile); /* fsync so later fsync's don't have to do
|
||||||
@ -51,24 +66,35 @@ main(int argc, char *argv[])
|
|||||||
printf("Simple write timing:\n");
|
printf("Simple write timing:\n");
|
||||||
/* write only */
|
/* write only */
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
for (i = 0; i < loops; i++)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
{
|
||||||
write(tmpfile, strout, 8192);
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
close(tmpfile);
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
close(tmpfile);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
printf("\twrite ");
|
printf("\twrite ");
|
||||||
print_elapse(start_t, elapse_t);
|
print_elapse(start_t, elapse_t);
|
||||||
printf("\n\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("Compare fsync before and after write's close:\n");
|
printf("\nCompare fsync times on write() and non-write() descriptor:\n");
|
||||||
|
printf("(If the times are similar, fsync() can sync data written\n on a different descriptor.)\n");
|
||||||
|
|
||||||
/* write, fsync, close */
|
/* write, fsync, close */
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
for (i = 0; i < loops; i++)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
{
|
||||||
write(tmpfile, strout, 8192);
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
fsync(tmpfile);
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
close(tmpfile);
|
write(tmpfile, strout, 8192);
|
||||||
|
fsync(tmpfile);
|
||||||
|
close(tmpfile);
|
||||||
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
|
/* do nothing but the open/close the tests are consistent. */
|
||||||
|
close(tmpfile);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
printf("\twrite, fsync, close ");
|
printf("\twrite, fsync, close ");
|
||||||
print_elapse(start_t, elapse_t);
|
print_elapse(start_t, elapse_t);
|
||||||
@ -76,15 +102,18 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* write, close, fsync */
|
/* write, close, fsync */
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
for (i = 0; i < loops; i++)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
{
|
||||||
write(tmpfile, strout, 8192);
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
close(tmpfile);
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
/* reopen file */
|
write(tmpfile, strout, 8192);
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
close(tmpfile);
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
/* reopen file */
|
||||||
fsync(tmpfile);
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
close(tmpfile);
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
|
fsync(tmpfile);
|
||||||
|
close(tmpfile);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
printf("\twrite, close, fsync ");
|
printf("\twrite, close, fsync ");
|
||||||
print_elapse(start_t, elapse_t);
|
print_elapse(start_t, elapse_t);
|
||||||
@ -93,10 +122,11 @@ main(int argc, char *argv[])
|
|||||||
printf("\nCompare one o_sync write to two:\n");
|
printf("\nCompare one o_sync write to two:\n");
|
||||||
|
|
||||||
/* 16k o_sync write */
|
/* 16k o_sync write */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 16384);
|
for (i = 0; i < loops; i++)
|
||||||
|
write(tmpfile, strout, 16384);
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\tone 16k o_sync write ");
|
printf("\tone 16k o_sync write ");
|
||||||
@ -104,11 +134,14 @@ main(int argc, char *argv[])
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/* 2*8k o_sync writes */
|
/* 2*8k o_sync writes */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
write(tmpfile, strout, 8192);
|
{
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\ttwo 8k o_sync writes ");
|
printf("\ttwo 8k o_sync writes ");
|
||||||
@ -119,10 +152,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
#ifdef OPEN_DATASYNC_FLAG
|
#ifdef OPEN_DATASYNC_FLAG
|
||||||
/* open_dsync, write */
|
/* open_dsync, write */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR | O_DSYNC)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR | O_DSYNC)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\topen o_dsync, write ");
|
printf("\topen o_dsync, write ");
|
||||||
@ -133,10 +167,11 @@ main(int argc, char *argv[])
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/* open_fsync, write */
|
/* open_fsync, write */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\topen o_sync, write ");
|
printf("\topen o_sync, write ");
|
||||||
@ -145,11 +180,14 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
#ifdef HAVE_FDATASYNC
|
#ifdef HAVE_FDATASYNC
|
||||||
/* write, fdatasync */
|
/* write, fdatasync */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
fdatasync(tmpfile);
|
{
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
fdatasync(tmpfile);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\twrite, fdatasync ");
|
printf("\twrite, fdatasync ");
|
||||||
@ -160,11 +198,14 @@ main(int argc, char *argv[])
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/* write, fsync, close */
|
/* write, fsync, close */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
fsync(tmpfile);
|
{
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
fsync(tmpfile);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\twrite, fsync, ");
|
printf("\twrite, fsync, ");
|
||||||
@ -176,11 +217,14 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
#ifdef OPEN_DATASYNC_FLAG
|
#ifdef OPEN_DATASYNC_FLAG
|
||||||
/* open_dsync, write */
|
/* open_dsync, write */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR | O_DSYNC)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR | O_DSYNC)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
write(tmpfile, strout, 8192);
|
{
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\topen o_dsync, write ");
|
printf("\topen o_dsync, write ");
|
||||||
@ -191,11 +235,14 @@ main(int argc, char *argv[])
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/* open_fsync, write */
|
/* open_fsync, write */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR | OPEN_SYNC_FLAG)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
write(tmpfile, strout, 8192);
|
{
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\topen o_sync, write ");
|
printf("\topen o_sync, write ");
|
||||||
@ -204,12 +251,15 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
#ifdef HAVE_FDATASYNC
|
#ifdef HAVE_FDATASYNC
|
||||||
/* write, fdatasync */
|
/* write, fdatasync */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
write(tmpfile, strout, 8192);
|
{
|
||||||
fdatasync(tmpfile);
|
write(tmpfile, strout, 8192);
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
fdatasync(tmpfile);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\twrite, fdatasync ");
|
printf("\twrite, fdatasync ");
|
||||||
@ -220,19 +270,22 @@ main(int argc, char *argv[])
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/* write, fsync, close */
|
/* write, fsync, close */
|
||||||
if ((tmpfile = open("/var/tmp/test_fsync.out", O_RDWR)) == -1)
|
if ((tmpfile = open(FSYNC_FILENAME, O_RDWR)) == -1)
|
||||||
die("can't open /var/tmp/test_fsync.out");
|
die("can't open /var/tmp/test_fsync.out");
|
||||||
gettimeofday(&start_t, NULL);
|
gettimeofday(&start_t, NULL);
|
||||||
write(tmpfile, strout, 8192);
|
for (i = 0; i < loops; i++)
|
||||||
write(tmpfile, strout, 8192);
|
{
|
||||||
fsync(tmpfile);
|
write(tmpfile, strout, 8192);
|
||||||
|
write(tmpfile, strout, 8192);
|
||||||
|
fsync(tmpfile);
|
||||||
|
}
|
||||||
gettimeofday(&elapse_t, NULL);
|
gettimeofday(&elapse_t, NULL);
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
printf("\twrite, fsync, ");
|
printf("\twrite, fsync, ");
|
||||||
print_elapse(start_t, elapse_t);
|
print_elapse(start_t, elapse_t);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
unlink("/var/tmp/test_fsync.out");
|
unlink(FSYNC_FILENAME);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -246,7 +299,7 @@ print_elapse(struct timeval start_t, struct timeval elapse_t)
|
|||||||
elapse_t.tv_usec += 1000000;
|
elapse_t.tv_usec += 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%ld.%06ld", (long) (elapse_t.tv_sec - start_t.tv_sec),
|
printf("%3ld.%06ld", (long) (elapse_t.tv_sec - start_t.tv_sec),
|
||||||
(long) (elapse_t.tv_usec - start_t.tv_usec));
|
(long) (elapse_t.tv_usec - start_t.tv_usec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user