Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
27668056
Commit
27668056
authored
Nov 15, 2019
by
antirez
Browse files
Expire cycle: tollerate less stale keys, expire cycle CPU in INFO.
parent
ffc7e509
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/expire.c
View file @
27668056
...
@@ -111,9 +111,11 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
...
@@ -111,9 +111,11 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
* little memory.
* little memory.
*/
*/
#define ACTIVE_EXPIRE_CYCLE_
BUC
KE
T
S_PER_LOOP 20
/*
HT buckets checked
. */
#define ACTIVE_EXPIRE_CYCLE_KE
Y
S_PER_LOOP 20
/*
Keys for each DB loop
. */
#define ACTIVE_EXPIRE_CYCLE_FAST_DURATION 1000
/* Microseconds. */
#define ACTIVE_EXPIRE_CYCLE_FAST_DURATION 1000
/* Microseconds. */
#define ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC 25
/* Percentage of CPU to use. */
#define ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC 25
/* Max % of CPU to use. */
#define ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE 10
/* % of stale keys after which
we do extra efforts. */
void
activeExpireCycle
(
int
type
)
{
void
activeExpireCycle
(
int
type
)
{
/* This function has some global state in order to continue the work
/* This function has some global state in order to continue the work
...
@@ -133,10 +135,15 @@ void activeExpireCycle(int type) {
...
@@ -133,10 +135,15 @@ void activeExpireCycle(int type) {
if
(
type
==
ACTIVE_EXPIRE_CYCLE_FAST
)
{
if
(
type
==
ACTIVE_EXPIRE_CYCLE_FAST
)
{
/* Don't start a fast cycle if the previous cycle did not exit
/* Don't start a fast cycle if the previous cycle did not exit
* for time limit. Also don't repeat a fast cycle for the same period
* for time limit, unless the percentage of estimated stale keys is
* too high. Also never repeat a fast cycle for the same period
* as the fast cycle total duration itself. */
* as the fast cycle total duration itself. */
if
(
!
timelimit_exit
)
return
;
if
(
!
timelimit_exit
&&
server
.
stat_expired_stale_perc
<
if
(
start
<
last_fast_cycle
+
ACTIVE_EXPIRE_CYCLE_FAST_DURATION
*
2
)
return
;
ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE
)
return
;
if
(
start
<
last_fast_cycle
+
ACTIVE_EXPIRE_CYCLE_FAST_DURATION
*
2
)
return
;
last_fast_cycle
=
start
;
last_fast_cycle
=
start
;
}
}
...
@@ -150,8 +157,8 @@ void activeExpireCycle(int type) {
...
@@ -150,8 +157,8 @@ void activeExpireCycle(int type) {
if
(
dbs_per_call
>
server
.
dbnum
||
timelimit_exit
)
if
(
dbs_per_call
>
server
.
dbnum
||
timelimit_exit
)
dbs_per_call
=
server
.
dbnum
;
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_EXPIRE_CYCLE_SLOW_TIME_PERC percentage of CPU
* per iteration. Since this function gets called with a frequency of
*
time
per iteration. Since this function gets called with a frequency of
* server.hz times per second, the following is the max amount of
* server.hz times per second, the following is the max amount of
* microseconds we can spend in this function. */
* microseconds we can spend in this function. */
timelimit
=
1000000
*
ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC
/
server
.
hz
/
100
;
timelimit
=
1000000
*
ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC
/
server
.
hz
/
100
;
...
@@ -207,8 +214,8 @@ void activeExpireCycle(int type) {
...
@@ -207,8 +214,8 @@ void activeExpireCycle(int type) {
ttl_sum
=
0
;
ttl_sum
=
0
;
ttl_samples
=
0
;
ttl_samples
=
0
;
if
(
num
>
ACTIVE_EXPIRE_CYCLE_
BUC
KE
T
S_PER_LOOP
)
if
(
num
>
ACTIVE_EXPIRE_CYCLE_KE
Y
S_PER_LOOP
)
num
=
ACTIVE_EXPIRE_CYCLE_
BUC
KE
T
S_PER_LOOP
;
num
=
ACTIVE_EXPIRE_CYCLE_KE
Y
S_PER_LOOP
;
/* Here we access the low level representation of the hash table
/* Here we access the low level representation of the hash table
* for speed concerns: this makes this code coupled with dict.c,
* for speed concerns: this makes this code coupled with dict.c,
...
@@ -268,9 +275,9 @@ void activeExpireCycle(int type) {
...
@@ -268,9 +275,9 @@ void activeExpireCycle(int type) {
}
}
}
}
/* We don't repeat the cycle for the current database if there are
/* We don't repeat the cycle for the current database if there are
*
less than 25% of keys found expired in the current DB. */
*
an acceptable amount of stale keys (logically expired but yet
// printf("[%d] Expired %d, sampled %d\n", type, (int) expired, (int) sampled);
* not reclained). */
}
while
(
expired
>
sampled
/
4
);
}
while
(
(
expired
*
100
/
sampled
)
>
ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE
);
}
}
elapsed
=
ustime
()
-
start
;
elapsed
=
ustime
()
-
start
;
...
...
src/server.c
View file @
27668056
...
@@ -4270,6 +4270,7 @@ sds genRedisInfoString(char *section) {
...
@@ -4270,6 +4270,7 @@ sds genRedisInfoString(char *section) {
"expired_keys:%lld
\r\n
"
"expired_keys:%lld
\r\n
"
"expired_stale_perc:%.2f
\r\n
"
"expired_stale_perc:%.2f
\r\n
"
"expired_time_cap_reached_count:%lld
\r\n
"
"expired_time_cap_reached_count:%lld
\r\n
"
"expire_cycle_cpu_milliseconds:%lld
\r\n
"
"evicted_keys:%lld
\r\n
"
"evicted_keys:%lld
\r\n
"
"keyspace_hits:%lld
\r\n
"
"keyspace_hits:%lld
\r\n
"
"keyspace_misses:%lld
\r\n
"
"keyspace_misses:%lld
\r\n
"
...
@@ -4297,6 +4298,7 @@ sds genRedisInfoString(char *section) {
...
@@ -4297,6 +4298,7 @@ sds genRedisInfoString(char *section) {
server
.
stat_expiredkeys
,
server
.
stat_expiredkeys
,
server
.
stat_expired_stale_perc
*
100
,
server
.
stat_expired_stale_perc
*
100
,
server
.
stat_expired_time_cap_reached_count
,
server
.
stat_expired_time_cap_reached_count
,
server
.
stat_expire_cycle_time_used
/
1000
,
server
.
stat_evictedkeys
,
server
.
stat_evictedkeys
,
server
.
stat_keyspace_hits
,
server
.
stat_keyspace_hits
,
server
.
stat_keyspace_misses
,
server
.
stat_keyspace_misses
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment