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
2f6fe5ce
Commit
2f6fe5ce
authored
Nov 14, 2019
by
antirez
Browse files
Expire cycle: introduce the new state needed for the new algo.
parent
8d50a832
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
2f6fe5ce
...
@@ -1077,10 +1077,12 @@ int dbSwapDatabases(long id1, long id2) {
...
@@ -1077,10 +1077,12 @@ int dbSwapDatabases(long id1, long id2) {
db1
->
dict
=
db2
->
dict
;
db1
->
dict
=
db2
->
dict
;
db1
->
expires
=
db2
->
expires
;
db1
->
expires
=
db2
->
expires
;
db1
->
avg_ttl
=
db2
->
avg_ttl
;
db1
->
avg_ttl
=
db2
->
avg_ttl
;
db1
->
expires_cursor
=
db2
->
expires_cursor
;
db2
->
dict
=
aux
.
dict
;
db2
->
dict
=
aux
.
dict
;
db2
->
expires
=
aux
.
expires
;
db2
->
expires
=
aux
.
expires
;
db2
->
avg_ttl
=
aux
.
avg_ttl
;
db2
->
avg_ttl
=
aux
.
avg_ttl
;
db2
->
expires_cursor
=
aux
.
expires_cursor
;
/* Now we need to handle clients blocked on lists: as an effect
/* Now we need to handle clients blocked on lists: as an effect
* of swapping the two DBs, a client that was waiting for list
* of swapping the two DBs, a client that was waiting for list
...
...
src/expire.c
View file @
2f6fe5ce
...
@@ -95,6 +95,10 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
...
@@ -95,6 +95,10 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
* executed, where the time limit is a percentage of the REDIS_HZ period
* 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_EXPIRE_CYCLE_SLOW_TIME_PERC define. */
#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
/* Percentage of CPU to use. */
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
* incrementally across calls. */
* incrementally across calls. */
...
@@ -231,6 +235,7 @@ void activeExpireCycle(int type) {
...
@@ -231,6 +235,7 @@ void activeExpireCycle(int type) {
}
}
elapsed
=
ustime
()
-
start
;
elapsed
=
ustime
()
-
start
;
server
.
stat_expire_cycle_time_used
+=
elapsed
;
latencyAddSampleIfNeeded
(
"expire-cycle"
,
elapsed
/
1000
);
latencyAddSampleIfNeeded
(
"expire-cycle"
,
elapsed
/
1000
);
/* Update our estimate of keys existing but yet to be expired.
/* Update our estimate of keys existing but yet to be expired.
...
...
src/server.c
View file @
2f6fe5ce
...
@@ -2745,6 +2745,7 @@ void resetServerStats(void) {
...
@@ -2745,6 +2745,7 @@ void resetServerStats(void) {
server
.
stat_expiredkeys
=
0
;
server
.
stat_expiredkeys
=
0
;
server
.
stat_expired_stale_perc
=
0
;
server
.
stat_expired_stale_perc
=
0
;
server
.
stat_expired_time_cap_reached_count
=
0
;
server
.
stat_expired_time_cap_reached_count
=
0
;
server
.
stat_expire_cycle_time_used
=
0
;
server
.
stat_evictedkeys
=
0
;
server
.
stat_evictedkeys
=
0
;
server
.
stat_keyspace_misses
=
0
;
server
.
stat_keyspace_misses
=
0
;
server
.
stat_keyspace_hits
=
0
;
server
.
stat_keyspace_hits
=
0
;
...
@@ -2848,6 +2849,7 @@ void initServer(void) {
...
@@ -2848,6 +2849,7 @@ void initServer(void) {
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
server
.
db
[
j
].
dict
=
dictCreate
(
&
dbDictType
,
NULL
);
server
.
db
[
j
].
dict
=
dictCreate
(
&
dbDictType
,
NULL
);
server
.
db
[
j
].
expires
=
dictCreate
(
&
keyptrDictType
,
NULL
);
server
.
db
[
j
].
expires
=
dictCreate
(
&
keyptrDictType
,
NULL
);
server
.
db
[
j
].
expires_cursor
=
0
;
server
.
db
[
j
].
blocking_keys
=
dictCreate
(
&
keylistDictType
,
NULL
);
server
.
db
[
j
].
blocking_keys
=
dictCreate
(
&
keylistDictType
,
NULL
);
server
.
db
[
j
].
ready_keys
=
dictCreate
(
&
objectKeyPointerValueDictType
,
NULL
);
server
.
db
[
j
].
ready_keys
=
dictCreate
(
&
objectKeyPointerValueDictType
,
NULL
);
server
.
db
[
j
].
watched_keys
=
dictCreate
(
&
keylistDictType
,
NULL
);
server
.
db
[
j
].
watched_keys
=
dictCreate
(
&
keylistDictType
,
NULL
);
...
...
src/server.h
View file @
2f6fe5ce
...
@@ -180,9 +180,6 @@ typedef long long ustime_t; /* microsecond time type. */
...
@@ -180,9 +180,6 @@ typedef long long ustime_t; /* microsecond time type. */
#define CONFIG_DEFAULT_PROTO_MAX_BULK_LEN (512ll*1024*1024)
/* Bulk request max size */
#define CONFIG_DEFAULT_PROTO_MAX_BULK_LEN (512ll*1024*1024)
/* Bulk request max size */
#define CONFIG_DEFAULT_TRACKING_TABLE_MAX_FILL 10
/* 10% tracking table max fill. */
#define CONFIG_DEFAULT_TRACKING_TABLE_MAX_FILL 10
/* 10% tracking table max fill. */
#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_EXPIRE_CYCLE_SLOW 0
#define ACTIVE_EXPIRE_CYCLE_SLOW 0
#define ACTIVE_EXPIRE_CYCLE_FAST 1
#define ACTIVE_EXPIRE_CYCLE_FAST 1
...
@@ -721,6 +718,7 @@ typedef struct redisDb {
...
@@ -721,6 +718,7 @@ typedef struct redisDb {
dict
*
watched_keys
;
/* WATCHED keys for MULTI/EXEC CAS */
dict
*
watched_keys
;
/* WATCHED keys for MULTI/EXEC CAS */
int
id
;
/* Database ID */
int
id
;
/* Database ID */
long
long
avg_ttl
;
/* Average TTL, just for stats */
long
long
avg_ttl
;
/* Average TTL, just for stats */
unsigned
long
expires_cursor
;
/* Cursor of the active expire cycle. */
list
*
defrag_later
;
/* List of key names to attempt to defrag one by one, gradually. */
list
*
defrag_later
;
/* List of key names to attempt to defrag one by one, gradually. */
}
redisDb
;
}
redisDb
;
...
@@ -1167,6 +1165,7 @@ struct redisServer {
...
@@ -1167,6 +1165,7 @@ struct redisServer {
long
long
stat_expiredkeys
;
/* Number of expired keys */
long
long
stat_expiredkeys
;
/* Number of expired keys */
double
stat_expired_stale_perc
;
/* Percentage of keys probably expired */
double
stat_expired_stale_perc
;
/* Percentage of keys probably expired */
long
long
stat_expired_time_cap_reached_count
;
/* Early expire cylce stops.*/
long
long
stat_expired_time_cap_reached_count
;
/* Early expire cylce stops.*/
long
long
stat_expire_cycle_time_used
;
/* Cumulative microseconds used. */
long
long
stat_evictedkeys
;
/* Number of evicted keys (maxmemory) */
long
long
stat_evictedkeys
;
/* Number of evicted keys (maxmemory) */
long
long
stat_keyspace_hits
;
/* Number of successful lookups of keys */
long
long
stat_keyspace_hits
;
/* Number of successful lookups of keys */
long
long
stat_keyspace_misses
;
/* Number of failed lookups of keys */
long
long
stat_keyspace_misses
;
/* Number of failed lookups of keys */
...
...
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