1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-27 00:12:01 +03:00

Instrument checkpoint sync calls.

Greg Smith, reviewed by Jeff Janes
This commit is contained in:
Robert Haas
2010-12-14 09:25:25 -05:00
parent 9878e295dc
commit 34c70c7ac4
3 changed files with 79 additions and 6 deletions

View File

@@ -20,6 +20,7 @@
#include "catalog/catalog.h"
#include "miscadmin.h"
#include "portability/instr_time.h"
#include "postmaster/bgwriter.h"
#include "storage/fd.h"
#include "storage/bufmgr.h"
@@ -927,6 +928,15 @@ mdsync(void)
PendingOperationEntry *entry;
int absorb_counter;
/* Statistics on sync times */
int processed = 0;
instr_time sync_start,
sync_end,
sync_diff;
uint64 elapsed;
uint64 longest = 0;
uint64 total_elapsed = 0;
/*
* This is only called during checkpoints, and checkpoints should only
* occur in processes that have created a pendingOpsTable.
@@ -1069,9 +1079,31 @@ mdsync(void)
seg = _mdfd_getseg(reln, entry->tag.forknum,
entry->tag.segno * ((BlockNumber) RELSEG_SIZE),
false, EXTENSION_RETURN_NULL);
if (log_checkpoints)
INSTR_TIME_SET_CURRENT(sync_start);
else
INSTR_TIME_SET_ZERO(sync_start);
if (seg != NULL &&
FileSync(seg->mdfd_vfd) >= 0)
{
if (log_checkpoints && (! INSTR_TIME_IS_ZERO(sync_start)))
{
INSTR_TIME_SET_CURRENT(sync_end);
sync_diff = sync_end;
INSTR_TIME_SUBTRACT(sync_diff, sync_start);
elapsed = INSTR_TIME_GET_MICROSEC(sync_diff);
if (elapsed > longest)
longest = elapsed;
total_elapsed += elapsed;
processed++;
elog(DEBUG1, "checkpoint sync: number=%d file=%s time=%.3f msec",
processed, FilePathName(seg->mdfd_vfd), (double) elapsed / 1000);
}
break; /* success; break out of retry loop */
}
/*
* XXX is there any point in allowing more than one retry?
@@ -1113,6 +1145,11 @@ mdsync(void)
elog(ERROR, "pendingOpsTable corrupted");
} /* end loop over hashtable entries */
/* Return sync performance metrics for report at checkpoint end */
CheckpointStats.ckpt_sync_rels = processed;
CheckpointStats.ckpt_longest_sync = longest;
CheckpointStats.ckpt_agg_sync_time = total_elapsed;
/* Flag successful completion of mdsync */
mdsync_in_progress = false;
}