Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8995440

Browse files
committed
In test_fsync, adjust test headings to match wal_sync_method values;
add more test cases for open_sync of different sizes.
1 parent1b393f4 commit8995440

File tree

1 file changed

+63
-107
lines changed

1 file changed

+63
-107
lines changed

‎src/tools/fsync/test_fsync.c

Lines changed: 63 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ voidtest_open(void);
4747
voidtest_non_sync(void);
4848
voidtest_sync(intwrites_per_op);
4949
voidtest_open_syncs(void);
50+
voidtest_open_sync(constchar*msg,intwrites_size);
5051
voidtest_file_descriptor_sync(void);
5152
voidprint_elapse(structtimevalstart_t,structtimevalstop_t);
5253
voiddie(char*str);
@@ -61,8 +62,6 @@ main(int argc, char *argv[])
6162

6263
test_open();
6364

64-
test_non_sync();
65-
6665
/* Test using 1 8k write */
6766
test_sync(1);
6867

@@ -73,6 +72,8 @@ main(int argc, char *argv[])
7372

7473
test_file_descriptor_sync();
7574

75+
test_non_sync();
76+
7677
unlink(filename);
7778

7879
return0;
@@ -105,7 +106,7 @@ handle_args(int argc, char *argv[])
105106
}
106107

107108
while ((option=getopt_long(argc,argv,"f:o:",
108-
long_options,&optindex))!=-1)
109+
long_options,&optindex))!=-1)
109110
{
110111
switch (option)
111112
{
@@ -126,7 +127,7 @@ handle_args(int argc, char *argv[])
126127
}
127128
}
128129

129-
printf("%d operations per test\n\n",ops_per_test);
130+
printf("%d operations per test\n",ops_per_test);
130131
}
131132

132133
void
@@ -161,58 +162,26 @@ test_open(void)
161162
close(tmpfile);
162163
}
163164

164-
void
165-
test_non_sync(void)
166-
{
167-
inttmpfile,ops;
168-
169-
/*
170-
* Test a simple write without fsync
171-
*/
172-
printf("Simple non-sync'ed write:\n");
173-
printf(LABEL_FORMAT,"8k write");
174-
fflush(stdout);
175-
176-
gettimeofday(&start_t,NULL);
177-
for (ops=0;ops<ops_per_test;ops++)
178-
{
179-
if ((tmpfile=open(filename,O_RDWR,0))==-1)
180-
die("Cannot open output file.");
181-
if (write(tmpfile,buf,WRITE_SIZE)!=WRITE_SIZE)
182-
die("write failed");
183-
close(tmpfile);
184-
}
185-
gettimeofday(&stop_t,NULL);
186-
print_elapse(start_t,stop_t);
187-
}
188-
189165
void
190166
test_sync(intwrites_per_op)
191167
{
192168
inttmpfile,ops,writes;
193169
boolfs_warning= false;
194170

195171
if (writes_per_op==1)
196-
printf("\nCompare file sync methods using one write:\n");
172+
printf("\nCompare file sync methods using one8kwrite:\n");
197173
else
198-
printf("\nCompare file sync methods using two writes:\n");
174+
printf("\nCompare file sync methods using two8kwrites:\n");
199175
printf("(in wal_sync_method preference order, except fdatasync\n");
200176
printf("is Linux's default)\n");
201177

202178
/*
203179
* Test open_datasync if available
204180
*/
205181
#ifdefOPEN_DATASYNC_FLAG
206-
if (writes_per_op==1)
207-
printf(LABEL_FORMAT,"open_datasync 8k write"
208-
#ifPG_O_DIRECT!=0
209-
"*"
210-
#endif
211-
);
212-
else
213-
printf(LABEL_FORMAT,"2 open_datasync 8k writes"
182+
printf(LABEL_FORMAT,"open_datasync"
214183
#ifPG_O_DIRECT!=0
215-
"*"
184+
" (non-direct I/O)*"
216185
#endif
217186
);
218187
fflush(stdout);
@@ -243,10 +212,7 @@ test_sync(int writes_per_op)
243212
}
244213
else
245214
{
246-
if (writes_per_op==1)
247-
printf(LABEL_FORMAT,"open_datasync 8k direct I/O write");
248-
else
249-
printf(LABEL_FORMAT,"2 open_datasync 8k direct I/O writes");
215+
printf(LABEL_FORMAT,"open_datasync (direct I/O)");
250216
fflush(stdout);
251217

252218
gettimeofday(&start_t,NULL);
@@ -262,8 +228,6 @@ test_sync(int writes_per_op)
262228
close(tmpfile);
263229
print_elapse(start_t,stop_t);
264230
}
265-
#else
266-
printf(NA_FORMAT,"o_direct","n/a\n");
267231
#endif
268232

269233
#else
@@ -274,10 +238,7 @@ test_sync(int writes_per_op)
274238
* Test fdatasync if available
275239
*/
276240
#ifdefHAVE_FDATASYNC
277-
if (writes_per_op==1)
278-
printf(LABEL_FORMAT,"8k write, fdatasync");
279-
else
280-
printf(LABEL_FORMAT,"8k write, 8k write, fdatasync");
241+
printf(LABEL_FORMAT,"fdatasync");
281242
fflush(stdout);
282243

283244
if ((tmpfile=open(filename,O_RDWR,0))==-1)
@@ -302,10 +263,7 @@ test_sync(int writes_per_op)
302263
/*
303264
* Test fsync
304265
*/
305-
if (writes_per_op==1)
306-
printf(LABEL_FORMAT,"8k write, fsync");
307-
else
308-
printf(LABEL_FORMAT,"8k write, 8k write, fsync");
266+
printf(LABEL_FORMAT,"fsync");
309267
fflush(stdout);
310268

311269
if ((tmpfile=open(filename,O_RDWR,0))==-1)
@@ -329,10 +287,7 @@ test_sync(int writes_per_op)
329287
* If fsync_writethrough is available, test as well
330288
*/
331289
#ifdefHAVE_FSYNC_WRITETHROUGH
332-
if (writes_per_op==1)
333-
printf(LABEL_FORMAT,"8k write, fsync_writethrough");
334-
else
335-
printf(LABEL_FORMAT,"8k write, 8k write, fsync_writethrough");
290+
printf(LABEL_FORMAT,"fsync_writethrough");
336291
fflush(stdout);
337292

338293
if ((tmpfile=open(filename,O_RDWR,0))==-1)
@@ -359,16 +314,9 @@ test_sync(int writes_per_op)
359314
* Test open_sync if available
360315
*/
361316
#ifdefOPEN_SYNC_FLAG
362-
if (writes_per_op==1)
363-
printf(LABEL_FORMAT,"open_sync 8k write"
364-
#ifPG_O_DIRECT!=0
365-
"*"
366-
#endif
367-
);
368-
else
369-
printf(LABEL_FORMAT,"2 open_sync 8k writes"
317+
printf(LABEL_FORMAT,"open_sync"
370318
#ifPG_O_DIRECT!=0
371-
"*"
319+
" (non-direct I/O)*"
372320
#endif
373321
);
374322
fflush(stdout);
@@ -399,10 +347,7 @@ test_sync(int writes_per_op)
399347
}
400348
else
401349
{
402-
if (writes_per_op==1)
403-
printf(LABEL_FORMAT,"open_sync 8k direct I/O write");
404-
else
405-
printf(LABEL_FORMAT,"2 open_sync 8k direct I/O writes");
350+
printf(LABEL_FORMAT,"open_sync (direct I/O)");
406351
fflush(stdout);
407352

408353
gettimeofday(&start_t,NULL);
@@ -418,8 +363,6 @@ test_sync(int writes_per_op)
418363
close(tmpfile);
419364
print_elapse(start_t,stop_t);
420365
}
421-
#else
422-
printf(NA_FORMAT,"o_direct","n/a\n");
423366
#endif
424367

425368
#else
@@ -428,7 +371,7 @@ test_sync(int writes_per_op)
428371

429372
#if defined(OPEN_DATASYNC_FLAG)|| defined(OPEN_SYNC_FLAG)
430373
if (PG_O_DIRECT!=0)
431-
printf("* This non-direct I/Ooption is not used by Postgres.\n");
374+
printf("* This non-direct I/Omode is not used by Postgres.\n");
432375
#endif
433376

434377
if (fs_warning)
@@ -441,14 +384,22 @@ test_sync(int writes_per_op)
441384
void
442385
test_open_syncs(void)
443386
{
444-
inttmpfile,ops;
387+
printf("\nCompare open_sync with different write sizes:\n");
388+
printf("(This is designed to compare the cost of writing 16k\n");
389+
printf("in different write open_sync sizes.)\n");
390+
391+
test_open_sync(" 1 16k open_sync write",16);
392+
test_open_sync(" 2 8k open_sync writes",8);
393+
test_open_sync(" 4 4k open_sync writes",4);
394+
test_open_sync(" 8 2k open_sync writes",2);
395+
test_open_sync("16 1k open_sync writes",1);
396+
}
445397

446-
/*
447-
* Compare 1 to 2 writes
448-
*/
449-
printf("\nCompare open_sync with different sizes:\n");
450-
printf("(This is designed to compare the cost of one large\n");
451-
printf("sync'ed write and two smaller sync'ed writes.)\n");
398+
399+
void
400+
test_open_sync(constchar*msg,intwrites_size)
401+
{
402+
inttmpfile,ops,writes;
452403

453404
/*
454405
* Test open_sync with different size files
@@ -458,14 +409,15 @@ test_open_syncs(void)
458409
printf(NA_FORMAT,"o_direct","n/a**\n");
459410
else
460411
{
461-
printf(LABEL_FORMAT,"open_sync 16k write");
412+
printf(LABEL_FORMAT,msg);
462413
fflush(stdout);
463414

464415
gettimeofday(&start_t,NULL);
465416
for (ops=0;ops<ops_per_test;ops++)
466417
{
467-
if (write(tmpfile,buf,WRITE_SIZE*2)!=WRITE_SIZE*2)
468-
die("write failed");
418+
for (writes=0;writes<16 /writes_size;writes++)
419+
if (write(tmpfile,buf,writes_size)!=writes_size)
420+
die("write failed");
469421
if (lseek(tmpfile,0,SEEK_SET)==-1)
470422
die("seek failed");
471423
}
@@ -474,27 +426,6 @@ test_open_syncs(void)
474426
print_elapse(start_t,stop_t);
475427
}
476428

477-
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG |PG_O_DIRECT,0))==-1)
478-
printf(NA_FORMAT,"o_direct","n/a**\n");
479-
else
480-
{
481-
printf(LABEL_FORMAT,"2 open_sync 8k writes");
482-
fflush(stdout);
483-
484-
gettimeofday(&start_t,NULL);
485-
for (ops=0;ops<ops_per_test;ops++)
486-
{
487-
if (write(tmpfile,buf,WRITE_SIZE)!=WRITE_SIZE)
488-
die("write failed");
489-
if (write(tmpfile,buf,WRITE_SIZE)!=WRITE_SIZE)
490-
die("write failed");
491-
if (lseek(tmpfile,0,SEEK_SET)==-1)
492-
die("seek failed");
493-
}
494-
gettimeofday(&stop_t,NULL);
495-
close(tmpfile);
496-
print_elapse(start_t,stop_t);
497-
}
498429
#else
499430
printf(NA_FORMAT,"open_sync","n/a\n");
500431
#endif
@@ -520,7 +451,7 @@ test_file_descriptor_sync(void)
520451
* first write, fsync and close, which is the
521452
* normal behavior without multiple descriptors
522453
*/
523-
printf(LABEL_FORMAT,"8kwrite, fsync, close");
454+
printf(LABEL_FORMAT,"write, fsync, close");
524455
fflush(stdout);
525456

526457
gettimeofday(&start_t,NULL);
@@ -549,7 +480,7 @@ test_file_descriptor_sync(void)
549480
* This simulates processes fsyncing each other's
550481
* writes.
551482
*/
552-
printf(LABEL_FORMAT,"8kwrite, close, fsync");
483+
printf(LABEL_FORMAT,"write, close, fsync");
553484
fflush(stdout);
554485

555486
gettimeofday(&start_t,NULL);
@@ -572,6 +503,31 @@ test_file_descriptor_sync(void)
572503

573504
}
574505

506+
void
507+
test_non_sync(void)
508+
{
509+
inttmpfile,ops;
510+
511+
/*
512+
* Test a simple write without fsync
513+
*/
514+
printf("\nNon-sync'ed 8k writes:\n");
515+
printf(LABEL_FORMAT,"write");
516+
fflush(stdout);
517+
518+
gettimeofday(&start_t,NULL);
519+
for (ops=0;ops<ops_per_test;ops++)
520+
{
521+
if ((tmpfile=open(filename,O_RDWR,0))==-1)
522+
die("Cannot open output file.");
523+
if (write(tmpfile,buf,WRITE_SIZE)!=WRITE_SIZE)
524+
die("write failed");
525+
close(tmpfile);
526+
}
527+
gettimeofday(&stop_t,NULL);
528+
print_elapse(start_t,stop_t);
529+
}
530+
575531
/*
576532
* print out the writes per second for tests
577533
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp