summaryrefslogtreecommitdiff
path: root/logger.c
diff options
context:
space:
mode:
authorGrant Mathews <grant.m.mathews@gmail.com>2017-02-17 16:04:37 -0800
committerdormando <dormando@rydia.net>2017-05-22 22:28:29 -0700
commitf0a3c4954fccc178c8e3e1948ff58cb3279d9783 (patch)
tree665188c658fd1fd21e7196874b5f67453c864892 /logger.c
parenta8c4a82787b8b6c256d61bd5c42fb7f92d1bae00 (diff)
downloadmemcached-f0a3c4954fccc178c8e3e1948ff58cb3279d9783.tar.gz
Sleep more aggressively in some threads
The logger and lru maintainer threads both adjust how long they sleep based on how busy they are. This adjustment should be exponential, to more quickly adjust to workloads. The logger thread in particular would only adjust 50 microseconds at a time, and was capped at 100 milliseconds of sleep, causing many unnecessary wakeups on an otherwise idle dev machine. Adjust this cap to 1 second.
Diffstat (limited to 'logger.c')
-rw-r--r--logger.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/logger.c b/logger.c
index 2338f9c..892bea8 100644
--- a/logger.c
+++ b/logger.c
@@ -454,8 +454,8 @@ static void logger_thread_sum_stats(struct logger_stats *ls) {
STATS_UNLOCK();
}
-#define MAX_LOGGER_SLEEP 100000
-#define MIN_LOGGER_SLEEP 0
+#define MAX_LOGGER_SLEEP 1000000
+#define MIN_LOGGER_SLEEP 1000
/* Primary logger thread routine */
static void *logger_thread(void *arg) {
@@ -466,7 +466,9 @@ static void *logger_thread(void *arg) {
logger *l;
struct logger_stats ls;
memset(&ls, 0, sizeof(struct logger_stats));
- if (to_sleep)
+
+ /* only sleep if we're *above* the minimum */
+ if (to_sleep > MIN_LOGGER_SLEEP)
usleep(to_sleep);
/* Call function to iterate each logger. */
@@ -482,10 +484,12 @@ static void *logger_thread(void *arg) {
/* TODO: abstract into a function and share with lru_crawler */
if (!found_logs) {
if (to_sleep < MAX_LOGGER_SLEEP)
- to_sleep += 50;
+ to_sleep += to_sleep / 8;
+ if (to_sleep > MAX_LOGGER_SLEEP)
+ to_sleep = MAX_LOGGER_SLEEP;
} else {
to_sleep /= 2;
- if (to_sleep < 50)
+ if (to_sleep < MIN_LOGGER_SLEEP)
to_sleep = MIN_LOGGER_SLEEP;
}
logger_thread_sum_stats(&ls);