Skip to content

Commit

Permalink
config add active-gc-cycle-non-gc-perc,active-gc-cycle-lookups-per-lo…
Browse files Browse the repository at this point in the history
…op,active-gc-cycle-slow-time-perc
  • Loading branch information
gd.zhou authored and patpatbear committed Jan 5, 2024
1 parent f428e33 commit c7c654d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
28 changes: 26 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,17 @@ void loadServerConfigFromString(char *config) {
}
} else if(!strcasecmp(argv[0], "dict-expand-max-idle-size")) {
setDictExpandMaxIdle(atoll(argv[1]));
}else {
} else if (!strcasecmp(argv[0],"active-gc-cycle-lookups-per-loop") && argc == 2) {
server.active_gc_cycle_lookups_per_loop = atoi(argv[1]);
} else if (!strcasecmp(argv[0],"active-gc-cycle-slow-time-perc") && argc == 2) {
server.active_gc_cycle_slow_time_perc = atoi(argv[1]);
if (server.active_gc_cycle_slow_time_perc > CONFIG_MAX_ACTIVE_GC_CYCLE_SLOW_TIME_PERC) server.active_gc_cycle_slow_time_perc = CONFIG_MAX_ACTIVE_GC_CYCLE_SLOW_TIME_PERC;
if (server.active_gc_cycle_slow_time_perc < CONFIG_MIN_ACTIVE_GC_CYCLE_SLOW_TIME_PERC) server.active_gc_cycle_slow_time_perc = CONFIG_MIN_ACTIVE_GC_CYCLE_SLOW_TIME_PERC;
} else if (!strcasecmp(argv[0],"active-gc-cycle-non-gc-perc") && argc == 2) {
server.active_gc_cycle_non_gc_perc = atoi(argv[1]);
if (server.active_gc_cycle_non_gc_perc > CONFIG_MAX_ACTIVE_GC_CYCLE_NON_GC_PERC) server.active_gc_cycle_non_gc_perc = CONFIG_MAX_ACTIVE_GC_CYCLE_NON_GC_PERC;
if (server.active_gc_cycle_non_gc_perc < CONFIG_MIN_ACTIVE_GC_CYCLE_NON_GC_PERC) server.active_gc_cycle_non_gc_perc = CONFIG_MIN_ACTIVE_GC_CYCLE_NON_GC_PERC;
} else {
err = "Bad directive or wrong number of arguments"; goto loaderr;
}
sdsfreesplitres(argv,argc);
Expand Down Expand Up @@ -1226,7 +1236,15 @@ void configSetCommand(client *c, struct redisServer *srv) {
disableWatchdog();
} config_set_numerical_field(
"non-last-write-delay-expire-time", srv->non_last_write_delay_expire_time, 0, LLONG_MAX) {

} config_set_numerical_field(
"active-gc-cycle-lookups-per-loop", srv->active_gc_cycle_lookups_per_loop, 0, LLONG_MAX) {
} config_set_numerical_field(
"active-gc-cycle-slow-time-perc", srv->active_gc_cycle_slow_time_perc, 0, LLONG_MAX) {
if (srv->active_gc_cycle_slow_time_perc < CONFIG_MIN_ACTIVE_GC_CYCLE_SLOW_TIME_PERC) srv->active_gc_cycle_slow_time_perc = CONFIG_MIN_ACTIVE_GC_CYCLE_SLOW_TIME_PERC;
if (srv->active_gc_cycle_slow_time_perc > CONFIG_MAX_ACTIVE_GC_CYCLE_SLOW_TIME_PERC) srv->active_gc_cycle_slow_time_perc = CONFIG_MAX_ACTIVE_GC_CYCLE_SLOW_TIME_PERC;
} config_set_numerical_field("active-gc-cycle-non-gc-perc", srv->active_gc_cycle_non_gc_perc, 0, LLONG_MAX) {
if (srv->active_gc_cycle_non_gc_perc < CONFIG_MIN_ACTIVE_GC_CYCLE_NON_GC_PERC) srv->active_gc_cycle_non_gc_perc = CONFIG_MIN_ACTIVE_GC_CYCLE_NON_GC_PERC;
if (srv->active_gc_cycle_non_gc_perc > CONFIG_MAX_ACTIVE_GC_CYCLE_NON_GC_PERC) srv->active_gc_cycle_non_gc_perc = CONFIG_MAX_ACTIVE_GC_CYCLE_NON_GC_PERC;
/* Memory fields.
* config_set_memory_field(name,var) */
} config_set_memory_field("maxmemory",srv->maxmemory) {
Expand Down Expand Up @@ -1392,6 +1410,9 @@ void configGetCommand(client *c, struct redisServer *srv) {
config_get_numerical_field("dict-expand-max-idle-size", getDictExpandMaxIdle());
config_get_numerical_field("crdt-offline-gid",srv->offline_peer_set);
config_get_numerical_field("non-last-write-delay-expire-time",srv->non_last_write_delay_expire_time);
config_get_numerical_field("active-gc-cycle-lookups-per-loop",srv->active_gc_cycle_lookups_per_loop);
config_get_numerical_field("active-gc-cycle-slow-time-perc",srv->active_gc_cycle_slow_time_perc);
config_get_numerical_field("active-gc-cycle-non-gc-perc",srv->active_gc_cycle_non_gc_perc);
/* Bool (yes/no) values */
config_get_bool_field("cluster-require-full-coverage",
srv->cluster_require_full_coverage);
Expand Down Expand Up @@ -2246,6 +2267,9 @@ int rewriteConfig(char *path) {
rewriteConfigNumericalOption(state,"non-last-write-delay-expire-time",server.non_last_write_delay_expire_time,CONFIG_DEFAULT_NON_LAST_WRITE_DELAY_EXPIRE_TIME);
rewriteConfigNameSpaceOption(state);
rewriteConfigVectorUnit(state);
rewriteConfigNumericalOption(state,"active-gc-cycle-non-gc-perc",server.active_gc_cycle_non_gc_perc,CONFIG_DEFAULT_ACTIVE_GC_CYCLE_NON_GC_PERC);
rewriteConfigNumericalOption(state,"active-gc-cycle-lookups-per-loop",server.active_gc_cycle_lookups_per_loop, ACTIVE_GC_CYCLE_LOOKUPS_PER_LOOP);
rewriteConfigNumericalOption(state,"active-gc-cycle-slow-time-perc",server.active_gc_cycle_slow_time_perc, ACTIVE_GC_CYCLE_SLOW_TIME_PERC);

/* Rewrite Sentinel config if in Sentinel mode. */
if (server.sentinel_mode) rewriteConfigSentinelOption(state);
Expand Down
18 changes: 9 additions & 9 deletions src/ctrip_crdt_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ int activeGcCycleTryGc(dict *d, dictEntry *de) {
*
* If type is ACTIVE_EXPIRE_CYCLE_SLOW, that normal expire cycle is
* executed, where the time limit is a percentage of the REDIS_HZ period
* as specified by the ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC define. */
* as specified by the ACTIVE_GC_CYCLE_SLOW_TIME_PERC define. */


typedef dict* (*getDictFunc)(redisDb *db);
Expand All @@ -278,7 +278,7 @@ void Gc(int type, unsigned int *current_db,int *timelimit_exit, long long *last_
* for time limt. Also don't repeat a fast cycle for the same period
* as the fast cycle total duration itself. */
if (!*timelimit_exit) return;
if (start < *last_fast_cycle + ACTIVE_EXPIRE_CYCLE_FAST_DURATION*2) return;
if (start < *last_fast_cycle + ACTIVE_GC_CYCLE_FAST_DURATION*2) return;
*last_fast_cycle = start;
}
/* We usually should test CRON_DBS_PER_CALL per iteration, with
Expand All @@ -291,16 +291,16 @@ void Gc(int type, unsigned int *current_db,int *timelimit_exit, long long *last_
if (dbs_per_call > server.dbnum || *timelimit_exit)
dbs_per_call = server.dbnum;

/* We can use at max ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC percentage of CPU time
/* We can use at max ACTIVE_GC_CYCLE_SLOW_TIME_PERC percentage of CPU time
* per iteration. Since this function gets called with a frequency of
* server.hz times per second, the following is the max amount of
* microseconds we can spend in this function. */
timelimit = 1000000*ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC/server.hz/100;
timelimit = 1000000*server.active_gc_cycle_slow_time_perc/server.hz/100;
*timelimit_exit = 0;
if (timelimit <= 0) timelimit = 1;

if (type == ACTIVE_GC_CYCLE_FAST)
timelimit = ACTIVE_EXPIRE_CYCLE_FAST_DURATION; /* in microseconds. */
timelimit = ACTIVE_GC_CYCLE_FAST_DURATION; /* in microseconds. */

for (j = 0; j < dbs_per_call && *timelimit_exit == 0; j++) {
int deleted;
Expand Down Expand Up @@ -333,8 +333,8 @@ void Gc(int type, unsigned int *current_db,int *timelimit_exit, long long *last_
* with an delete set, checking for deleted ones. */
deleted = 0;

if (num > ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP)
num = ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP;
if (num > server.active_gc_cycle_lookups_per_loop)
num = server.active_gc_cycle_lookups_per_loop;

while (num--) {
dictEntry *de;
Expand All @@ -355,9 +355,9 @@ void Gc(int type, unsigned int *current_db,int *timelimit_exit, long long *last_
break;
}
}
/* We don't repeat the cycle if there are less than 25% of keys
/* We don't repeat the cycle if there are less than {server.non_gc_perc}% of keys
* found deleted in the current DB. */
} while (deleted > ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP/4);
} while (deleted > server.active_gc_cycle_lookups_per_loop * server.active_gc_cycle_non_gc_perc/100 );
}
elapsed = ustime()-start;
latencyAddSampleIfNeeded((char *)name,elapsed/1000);
Expand Down
3 changes: 3 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,9 @@ void initServerConfig(struct redisServer *srv) {
srv->offline_peer_set = 0;
srv->peer_set = 0;
srv->non_last_write_delay_expire_time = CONFIG_DEFAULT_NON_LAST_WRITE_DELAY_EXPIRE_TIME; // 15min
srv->active_gc_cycle_non_gc_perc = CONFIG_DEFAULT_ACTIVE_GC_CYCLE_NON_GC_PERC;
srv->active_gc_cycle_lookups_per_loop = ACTIVE_GC_CYCLE_LOOKUPS_PER_LOOP;
srv->active_gc_cycle_slow_time_perc = ACTIVE_GC_CYCLE_SLOW_TIME_PERC;
unsigned int lruclock = getLRUClock();
atomicSet(srv->lruclock,lruclock);
resetServerSaveParams(srv);
Expand Down
13 changes: 12 additions & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,18 @@ long long get_min_backstream_vcu();
#define CONFIG_DEFAULT_GID -1
#define CONFIG_DEFAULT_VECTORCLOCK_UNIT -1
#define CONFIG_DEFAULT_NON_LAST_WRITE_DELAY_EXPIRE_TIME (15*60*1000) /* delay expire 15min */
#define CONFIG_DEFAULT_ACTIVE_GC_CYCLE_NON_GC_PERC 25
#define CONFIG_MAX_ACTIVE_GC_CYCLE_NON_GC_PERC 100
#define CONFIG_MIN_ACTIVE_GC_CYCLE_NON_GC_PERC 0
#define CONFIG_MAX_ACTIVE_GC_CYCLE_SLOW_TIME_PERC 100
#define CONFIG_MIN_ACTIVE_GC_CYCLE_SLOW_TIME_PERC 0

#define ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP 20 /* Loopkups per loop. */
#define ACTIVE_EXPIRE_CYCLE_FAST_DURATION 1000 /* Microseconds */
#define ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC 25 /* CPU max % for keys collection */
#define ACTIVE_GC_CYCLE_LOOKUPS_PER_LOOP 20 /* Loopkups per loop. */
#define ACTIVE_GC_CYCLE_FAST_DURATION 1000 /* Microseconds */
#define ACTIVE_GC_CYCLE_SLOW_TIME_PERC 25 /* CPU max % for keys collection */
#define ACTIVE_EXPIRE_CYCLE_SLOW 0
#define ACTIVE_EXPIRE_CYCLE_FAST 1
#define ACTIVE_GC_CYCLE_SLOW 0
Expand Down Expand Up @@ -1329,7 +1337,10 @@ struct redisServer {
int restart_lazy_peerof_time;
long long stat_gc_hits; /* Number of successful gc */
long long stat_gc_misses; /* Number of failed gc */
int non_last_write_delay_expire_time; /* last write gid expire=>del, other gid after N milliseconds of expire */
int non_last_write_delay_expire_time; /* last write gid expire=>del, other gid after N milliseconds of expire */
int active_gc_cycle_lookups_per_loop; /* gc Loopkups per loop. */
int active_gc_cycle_slow_time_perc; /* gc CPU max % for keys collection */
int active_gc_cycle_non_gc_perc; /* We don't repeat the cycle if there are less than max % of keys*/
};

typedef struct pubsubPattern {
Expand Down

0 comments on commit c7c654d

Please sign in to comment.