improve log performance by disabling O_SYNC by default (and use fdatasync instead)

This commit is contained in:
Sears Russell 2009-09-12 16:20:13 +00:00
parent e48bc7adf3
commit 4689582cb5
7 changed files with 31 additions and 13 deletions

View file

@ -64,7 +64,7 @@ char * stasis_store_file_name = "storefile.txt";
#ifdef STASIS_LOG_FILE_MODE
int stasis_log_file_mode = STASIS_LOG_FILE_MODE;
#else
int stasis_log_file_mode = (O_CREAT | O_RDWR | O_SYNC);
int stasis_log_file_mode = (O_CREAT | O_RDWR);
#endif
#ifdef STASIS_LOG_FILE_PERMISSIONS
@ -74,6 +74,12 @@ int stasis_log_file_permissions = (S_IRUSR | S_IWUSR | S_IRGRP|
S_IWGRP | S_IROTH | S_IWOTH);
#endif
#ifdef STASIS_LOG_SOFTCOMMIT
int stasis_log_softcommit = STASIS_LOG_SOFTCOMMIT;
#else
int stasis_log_softcommit = 0;
#endif
#ifdef STASIS_LOG_DIR
const char* stasis_log_dir_name = STASIS_LOG_DIR;
#else

View file

@ -409,11 +409,17 @@ static void syncLog_LogWriter(stasis_log_t * log,
pthread_mutex_unlock(&sw->write_mutex);
fflush(sw->fp);
// If we opened the logfile with O_SYNC, fflush() is sufficient.
// Otherwise, we're running in soft commit mode and need to manually force
// the log before allowing page writeback.
if(sw->softcommit && mode == LOG_FORCE_WAL) {
// We can skip the fsync if we opened with O_SYNC, or if we're in softcommit mode, and not forcing for WAL.
if(sw->softcommit && mode == LOG_FORCE_WAL // soft commit mode; syncing for wal
|| !(sw->softcommit || (sw->filemode & O_SYNC)) // neither soft commit nor opened with O_SYNC
) {
#ifdef HAVE_FDATASYNC
fdatasync(fileno(sw->fp));
#else
fsync(fileno(sw->fp));
#endif
}
// update flushedLSN after fflush returns.
@ -749,7 +755,7 @@ static lsn_t firstLogEntry_LogWriter(stasis_log_t* log) {
}
stasis_log_t* stasis_log_safe_writes_open(const char * filename,
int filemode, int fileperm) {
int filemode, int fileperm, int softcommit) {
stasis_log_t proto = {
sizeofInternalLogEntry_LogWriter, // sizeof_internal_entry
@ -775,7 +781,7 @@ stasis_log_t* stasis_log_safe_writes_open(const char * filename,
}
sw->filemode = filemode;
sw->fileperm = fileperm;
sw->softcommit = !(filemode & O_SYNC);
sw->softcommit = softcommit;
stasis_log_t* log = malloc(sizeof(*log));
memcpy(log,&proto, sizeof(proto));

View file

@ -76,7 +76,8 @@ int Tinit() {
if(LOG_TO_FILE == stasis_log_type) {
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
stasis_log_file_mode,
stasis_log_file_permissions);
stasis_log_file_permissions,
stasis_log_softcommit);
stasis_log_file->group_force =
stasis_log_group_force_init(stasis_log_file, 10 * 1000 * 1000); // timeout in nsec; want 10msec.
} else if(LOG_TO_MEMORY == stasis_log_type) {

View file

@ -77,6 +77,7 @@ extern int stasis_log_type;
extern char * stasis_log_file_name;
extern int stasis_log_file_mode;
extern int stasis_log_file_permissions;
extern int stasis_log_softcommit;
extern char * stasis_store_file_name;

View file

@ -56,7 +56,8 @@ BEGIN_C_DECLS
*/
stasis_log_t* stasis_log_safe_writes_open(const char * filename,
int filemode,
int fileperm);
int fileperm,
int softcommit);
/**
Actually deletes the log file that may have been written to disk! Danger!!

View file

@ -432,7 +432,8 @@ void reopenLogWorkload(int truncating) {
if(LOG_TO_FILE == stasis_log_type) {
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
stasis_log_file_mode,
stasis_log_file_permissions);
stasis_log_file_permissions,
stasis_log_softcommit);
} else if(LOG_TO_MEMORY == stasis_log_type) {
stasis_log_file = stasis_log_impl_in_memory_open();
} else {
@ -465,7 +466,8 @@ void reopenLogWorkload(int truncating) {
if(LOG_TO_FILE == stasis_log_type) {
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
stasis_log_file_mode,
stasis_log_file_permissions);
stasis_log_file_permissions,
stasis_log_softcommit);
} else if(LOG_TO_MEMORY == stasis_log_type) {
stasis_log_file = stasis_log_impl_in_memory_open();
} else {

View file

@ -67,7 +67,8 @@ int main() {
stasis_log_t* log;
if(NULL == (log = stasis_log_safe_writes_open(stasis_log_file_name,
stasis_log_file_mode,
stasis_log_file_permissions))){
stasis_log_file_permissions,
stasis_log_softcommit))){
printf("Couldn't open log.\n");
}