Skip to content

Commit

Permalink
make HOT/WARM ratios starttime tunable.
Browse files Browse the repository at this point in the history
runtime tunable is difficult and may require either atomics, or adding an
extra items.c array. Adjusting the value would roll through and lock each
LRU before changing the value.
  • Loading branch information
dormando committed Jan 9, 2015
1 parent 76e1d97 commit 8d6bf78
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions items.c
Expand Up @@ -803,9 +803,9 @@ static int lru_pull_tail(const int orig_id, const int cur_lru,
/* FIXME: Hardcoded percentage */
switch (cur_lru) {
case HOT_LRU:
limit = total_chunks * 32 / 100;
limit = total_chunks * settings.hot_lru_pct / 100;
case WARM_LRU:
limit = total_chunks * 32 / 100;
limit = total_chunks * settings.warm_lru_pct / 100;
if (sizes[id] > limit) {
itemstats[id].moves_to_cold++;
move_to_lru = COLD_LRU;
Expand Down
38 changes: 37 additions & 1 deletion memcached.c
Expand Up @@ -236,6 +236,8 @@ static void settings_init(void) {
settings.lru_crawler_sleep = 100;
settings.lru_crawler_tocrawl = 0;
settings.lru_maintainer_thread = false;
settings.hot_lru_pct = 32;
settings.warm_lru_pct = 32;
settings.hashpower_init = 0;
settings.slab_reassign = false;
settings.slab_automove = 0;
Expand Down Expand Up @@ -2675,6 +2677,9 @@ static void process_stat_settings(ADD_STAT add_stats, void *c) {
APPEND_STAT("tail_repair_time", "%d", settings.tail_repair_time);
APPEND_STAT("flush_enabled", "%s", settings.flush_enabled ? "yes" : "no");
APPEND_STAT("hash_algorithm", "%s", settings.hash_algorithm);
APPEND_STAT("lru_maintainer_thread", "%s", settings.lru_maintainer_thread ? "yes" : "no");
APPEND_STAT("hot_lru_pct", "%d", settings.hot_lru_pct);
APPEND_STAT("warm_lru_pct", "%d", settings.hot_lru_pct);
}

static void conn_to_str(const conn *c, char *buf) {
Expand Down Expand Up @@ -5077,7 +5082,9 @@ int main (int argc, char **argv) {
LRU_CRAWLER,
LRU_CRAWLER_SLEEP,
LRU_CRAWLER_TOCRAWL,
LRU_MAINTAINER
LRU_MAINTAINER,
HOT_LRU_PCT,
WARM_LRU_PCT
};
char *const subopts_tokens[] = {
[MAXCONNS_FAST] = "maxconns_fast",
Expand All @@ -5090,6 +5097,8 @@ int main (int argc, char **argv) {
[LRU_CRAWLER_SLEEP] = "lru_crawler_sleep",
[LRU_CRAWLER_TOCRAWL] = "lru_crawler_tocrawl",
[LRU_MAINTAINER] = "lru_maintainer",
[HOT_LRU_PCT] = "hot_lru_pct",
[WARM_LRU_PCT] = "warm_lru_pct",
NULL
};

Expand Down Expand Up @@ -5424,6 +5433,28 @@ int main (int argc, char **argv) {
return 1;
}
break;
case HOT_LRU_PCT:
if (subopts_value == NULL) {
fprintf(stderr, "Missing hot_lru_pct argument\n");
return 1;
};
settings.hot_lru_pct = atoi(subopts_value);
if (settings.hot_lru_pct < 1 || settings.hot_lru_pct >= 80) {
fprintf(stderr, "hot_lru_pct must be > 1 and < 80\n");
return 1;
}
break;
case WARM_LRU_PCT:
if (subopts_value == NULL) {
fprintf(stderr, "Missing warm_lru_pct argument\n");
return 1;
};
settings.warm_lru_pct = atoi(subopts_value);
if (settings.warm_lru_pct < 1 || settings.warm_lru_pct >= 80) {
fprintf(stderr, "warm_lru_pct must be > 1 and < 80\n");
return 1;
}
break;
default:
printf("Illegal suboption \"%s\"\n", subopts_value);
return 1;
Expand All @@ -5437,6 +5468,11 @@ int main (int argc, char **argv) {
}
}

if (settings.lru_maintainer_thread && settings.hot_lru_pct + settings.warm_lru_pct > 80) {
fprintf(stderr, "hot_lru_pct + warm_lru_pct cannot be more than 80%% combined\n");
exit(EX_USAGE);
}

if (hash_init(hash_type) != 0) {
fprintf(stderr, "Failed to initialize hash_algorithm!\n");
exit(EX_USAGE);
Expand Down
2 changes: 2 additions & 0 deletions memcached.h
Expand Up @@ -332,6 +332,8 @@ struct settings {
char *hash_algorithm; /* Hash algorithm in use */
int lru_crawler_sleep; /* Microsecond sleep between items */
uint32_t lru_crawler_tocrawl; /* Number of items to crawl per run */
int hot_lru_pct; /* percentage of slab space for HOT_LRU */
int warm_lru_pct; /* percentage of slab space for WARM_LRU */
};

extern struct stats stats;
Expand Down
2 changes: 1 addition & 1 deletion t/binary.t
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::More tests => 3615;
use Test::More tests => 3624;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
Expand Down

0 comments on commit 8d6bf78

Please sign in to comment.