avoid extra calls to gettimeofday() when the log is not durable; set group commit to wait for 10msec, not 100...

This commit is contained in:
Sears Russell 2009-02-03 05:36:33 +00:00
parent 95e9158847
commit 4ce4491097

View file

@ -197,42 +197,47 @@ static void groupCommit(stasis_log_t* log, lsn_t lsn) {
static pthread_mutex_t check_commit = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t check_commit = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t tooFewXacts = PTHREAD_COND_INITIALIZER; static pthread_cond_t tooFewXacts = PTHREAD_COND_INITIALIZER;
struct timeval now;
struct timespec timeout;
pthread_mutex_lock(&check_commit); pthread_mutex_lock(&check_commit);
if(log->first_unstable_lsn(log,LOG_FORCE_COMMIT) > lsn) { if(log->first_unstable_lsn(log,LOG_FORCE_COMMIT) > lsn) {
pthread_mutex_unlock(&check_commit); pthread_mutex_unlock(&check_commit);
return; return;
} }
gettimeofday(&now, NULL); if(log->is_durable(log)) {
timeout.tv_sec = now.tv_sec; struct timeval now;
timeout.tv_nsec = now.tv_usec * 1000; struct timespec timeout;
// 0123456789 <- number of zeros on the next three lines...
timeout.tv_nsec += 100000000; // wait ten msec.
if(timeout.tv_nsec > 1000000000) {
timeout.tv_nsec -= 1000000000;
timeout.tv_sec++;
}
pendingCommits++; gettimeofday(&now, NULL);
int xactcount = TactiveTransactionCount(); timeout.tv_sec = now.tv_sec;
if((log->is_durable(log) && xactcount > 1 && pendingCommits < xactcount) || timeout.tv_nsec = now.tv_usec * 1000;
(xactcount > 20 && pendingCommits < (int)((double)xactcount * 0.95))) { // 0123456789 <- number of zeros on the next three lines...
int retcode; timeout.tv_nsec += 10000000; // wait ten msec.
while(ETIMEDOUT != (retcode = pthread_cond_timedwait(&tooFewXacts, &check_commit, &timeout))) { if(timeout.tv_nsec > 1000000000) {
if(retcode != 0) { timeout.tv_nsec -= 1000000000;
printf("Warning: %s:%d: pthread_cond_timedwait was interrupted by " timeout.tv_sec++;
"a signal in groupCommit(). Acting as though it timed out.\n", }
__FILE__, __LINE__);
break; pendingCommits++;
} int xactcount = TactiveTransactionCount();
if(log->first_unstable_lsn(log,LOG_FORCE_COMMIT) > lsn) { if((xactcount > 1 && pendingCommits < xactcount) ||
pendingCommits--; (xactcount > 20 && pendingCommits < (int)((double)xactcount * 0.95))) {
pthread_mutex_unlock(&check_commit); int retcode;
return; while(ETIMEDOUT != (retcode = pthread_cond_timedwait(&tooFewXacts, &check_commit, &timeout))) {
if(retcode != 0) {
printf("Warning: %s:%d: pthread_cond_timedwait was interrupted by "
"a signal in groupCommit(). Acting as though it timed out.\n",
__FILE__, __LINE__);
break;
}
if(log->first_unstable_lsn(log,LOG_FORCE_COMMIT) > lsn) {
pendingCommits--;
pthread_mutex_unlock(&check_commit);
return;
}
} }
} }
} else {
pendingCommits++;
} }
if(log->first_unstable_lsn(log,LOG_FORCE_COMMIT) <= lsn) { if(log->first_unstable_lsn(log,LOG_FORCE_COMMIT) <= lsn) {
log->force_tail(log, LOG_FORCE_COMMIT); log->force_tail(log, LOG_FORCE_COMMIT);