improve log performance by disabling O_SYNC by default (and use fdatasync instead)
This commit is contained in:
parent
e48bc7adf3
commit
4689582cb5
7 changed files with 31 additions and 13 deletions
|
@ -64,7 +64,7 @@ char * stasis_store_file_name = "storefile.txt";
|
||||||
#ifdef STASIS_LOG_FILE_MODE
|
#ifdef STASIS_LOG_FILE_MODE
|
||||||
int stasis_log_file_mode = STASIS_LOG_FILE_MODE;
|
int stasis_log_file_mode = STASIS_LOG_FILE_MODE;
|
||||||
#else
|
#else
|
||||||
int stasis_log_file_mode = (O_CREAT | O_RDWR | O_SYNC);
|
int stasis_log_file_mode = (O_CREAT | O_RDWR);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef STASIS_LOG_FILE_PERMISSIONS
|
#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);
|
S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef STASIS_LOG_SOFTCOMMIT
|
||||||
|
int stasis_log_softcommit = STASIS_LOG_SOFTCOMMIT;
|
||||||
|
#else
|
||||||
|
int stasis_log_softcommit = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef STASIS_LOG_DIR
|
#ifdef STASIS_LOG_DIR
|
||||||
const char* stasis_log_dir_name = STASIS_LOG_DIR;
|
const char* stasis_log_dir_name = STASIS_LOG_DIR;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -409,11 +409,17 @@ static void syncLog_LogWriter(stasis_log_t * log,
|
||||||
pthread_mutex_unlock(&sw->write_mutex);
|
pthread_mutex_unlock(&sw->write_mutex);
|
||||||
|
|
||||||
fflush(sw->fp);
|
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
|
// We can skip the fsync if we opened with O_SYNC, or if we're in softcommit mode, and not forcing for WAL.
|
||||||
// the log before allowing page writeback.
|
|
||||||
if(sw->softcommit && mode == LOG_FORCE_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));
|
fsync(fileno(sw->fp));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// update flushedLSN after fflush returns.
|
// 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,
|
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 = {
|
stasis_log_t proto = {
|
||||||
sizeofInternalLogEntry_LogWriter, // sizeof_internal_entry
|
sizeofInternalLogEntry_LogWriter, // sizeof_internal_entry
|
||||||
|
@ -775,7 +781,7 @@ stasis_log_t* stasis_log_safe_writes_open(const char * filename,
|
||||||
}
|
}
|
||||||
sw->filemode = filemode;
|
sw->filemode = filemode;
|
||||||
sw->fileperm = fileperm;
|
sw->fileperm = fileperm;
|
||||||
sw->softcommit = !(filemode & O_SYNC);
|
sw->softcommit = softcommit;
|
||||||
|
|
||||||
stasis_log_t* log = malloc(sizeof(*log));
|
stasis_log_t* log = malloc(sizeof(*log));
|
||||||
memcpy(log,&proto, sizeof(proto));
|
memcpy(log,&proto, sizeof(proto));
|
||||||
|
|
|
@ -76,7 +76,8 @@ int Tinit() {
|
||||||
if(LOG_TO_FILE == stasis_log_type) {
|
if(LOG_TO_FILE == stasis_log_type) {
|
||||||
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
||||||
stasis_log_file_mode,
|
stasis_log_file_mode,
|
||||||
stasis_log_file_permissions);
|
stasis_log_file_permissions,
|
||||||
|
stasis_log_softcommit);
|
||||||
stasis_log_file->group_force =
|
stasis_log_file->group_force =
|
||||||
stasis_log_group_force_init(stasis_log_file, 10 * 1000 * 1000); // timeout in nsec; want 10msec.
|
stasis_log_group_force_init(stasis_log_file, 10 * 1000 * 1000); // timeout in nsec; want 10msec.
|
||||||
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
||||||
|
|
|
@ -77,6 +77,7 @@ extern int stasis_log_type;
|
||||||
extern char * stasis_log_file_name;
|
extern char * stasis_log_file_name;
|
||||||
extern int stasis_log_file_mode;
|
extern int stasis_log_file_mode;
|
||||||
extern int stasis_log_file_permissions;
|
extern int stasis_log_file_permissions;
|
||||||
|
extern int stasis_log_softcommit;
|
||||||
|
|
||||||
extern char * stasis_store_file_name;
|
extern char * stasis_store_file_name;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,8 @@ BEGIN_C_DECLS
|
||||||
*/
|
*/
|
||||||
stasis_log_t* stasis_log_safe_writes_open(const char * filename,
|
stasis_log_t* stasis_log_safe_writes_open(const char * filename,
|
||||||
int filemode,
|
int filemode,
|
||||||
int fileperm);
|
int fileperm,
|
||||||
|
int softcommit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Actually deletes the log file that may have been written to disk! Danger!!
|
Actually deletes the log file that may have been written to disk! Danger!!
|
||||||
|
|
|
@ -432,7 +432,8 @@ void reopenLogWorkload(int truncating) {
|
||||||
if(LOG_TO_FILE == stasis_log_type) {
|
if(LOG_TO_FILE == stasis_log_type) {
|
||||||
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
||||||
stasis_log_file_mode,
|
stasis_log_file_mode,
|
||||||
stasis_log_file_permissions);
|
stasis_log_file_permissions,
|
||||||
|
stasis_log_softcommit);
|
||||||
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
||||||
stasis_log_file = stasis_log_impl_in_memory_open();
|
stasis_log_file = stasis_log_impl_in_memory_open();
|
||||||
} else {
|
} else {
|
||||||
|
@ -465,7 +466,8 @@ void reopenLogWorkload(int truncating) {
|
||||||
if(LOG_TO_FILE == stasis_log_type) {
|
if(LOG_TO_FILE == stasis_log_type) {
|
||||||
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
||||||
stasis_log_file_mode,
|
stasis_log_file_mode,
|
||||||
stasis_log_file_permissions);
|
stasis_log_file_permissions,
|
||||||
|
stasis_log_softcommit);
|
||||||
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
||||||
stasis_log_file = stasis_log_impl_in_memory_open();
|
stasis_log_file = stasis_log_impl_in_memory_open();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -67,7 +67,8 @@ int main() {
|
||||||
stasis_log_t* log;
|
stasis_log_t* log;
|
||||||
if(NULL == (log = stasis_log_safe_writes_open(stasis_log_file_name,
|
if(NULL == (log = stasis_log_safe_writes_open(stasis_log_file_name,
|
||||||
stasis_log_file_mode,
|
stasis_log_file_mode,
|
||||||
stasis_log_file_permissions))){
|
stasis_log_file_permissions,
|
||||||
|
stasis_log_softcommit))){
|
||||||
printf("Couldn't open log.\n");
|
printf("Couldn't open log.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue