@@ -109,6 +109,9 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
109
109
* of already expired keys in the database is estimated to be lower than
110
110
* a given percentage, in order to avoid doing too much work to gain too
111
111
* little memory.
112
+ *
113
+ * The configured expire "effort" will modify the baseline parameters in
114
+ * order to do more work in both the fast and slow expire cycles.
112
115
*/
113
116
114
117
#define ACTIVE_EXPIRE_CYCLE_KEYS_PER_LOOP 20 /* Keys for each DB loop. */
@@ -118,6 +121,21 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
118
121
we do extra efforts. */
119
122
120
123
void activeExpireCycle (int type ) {
124
+ /* Adjust the running parameters according to the configured expire
125
+ * effort. The default effort is 1, and the maximum configurable effort
126
+ * is 10. */
127
+ unsigned long
128
+ effort = server .active_expire_effort ,
129
+ config_keys_per_loop = ACTIVE_EXPIRE_CYCLE_KEYS_PER_LOOP +
130
+ ACTIVE_EXPIRE_CYCLE_KEYS_PER_LOOP /4 * effort ,
131
+ config_cycle_fast_duration = ACTIVE_EXPIRE_CYCLE_FAST_DURATION *
132
+ ACTIVE_EXPIRE_CYCLE_FAST_DURATION /4 * effort ,
133
+ config_cycle_slow_time_perc = ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC +
134
+ 2 * effort ,
135
+ config_cycle_acceptable_stale = ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE -
136
+ effort ;
137
+ if (config_cycle_acceptable_stale < 1 ) config_cycle_acceptable_stale = 1 ;
138
+
121
139
/* This function has some global state in order to continue the work
122
140
* incrementally across calls. */
123
141
static unsigned int current_db = 0 ; /* Last DB tested. */
@@ -138,10 +156,11 @@ void activeExpireCycle(int type) {
138
156
* for time limit, unless the percentage of estimated stale keys is
139
157
* too high. Also never repeat a fast cycle for the same period
140
158
* as the fast cycle total duration itself. */
141
- if (!timelimit_exit && server .stat_expired_stale_perc <
142
- ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE ) return ;
159
+ if (!timelimit_exit &&
160
+ server .stat_expired_stale_perc < config_cycle_acceptable_stale )
161
+ return ;
143
162
144
- if (start < last_fast_cycle + ACTIVE_EXPIRE_CYCLE_FAST_DURATION * 2 )
163
+ if (start < last_fast_cycle + ( long long ) config_cycle_fast_duration * 2 )
145
164
return ;
146
165
147
166
last_fast_cycle = start ;
@@ -157,16 +176,16 @@ void activeExpireCycle(int type) {
157
176
if (dbs_per_call > server .dbnum || timelimit_exit )
158
177
dbs_per_call = server .dbnum ;
159
178
160
- /* We can use at max ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC percentage of CPU
179
+ /* We can use at max 'config_cycle_slow_time_perc' percentage of CPU
161
180
* time per iteration. Since this function gets called with a frequency of
162
181
* server.hz times per second, the following is the max amount of
163
182
* microseconds we can spend in this function. */
164
- timelimit = 1000000 * ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC /server .hz /100 ;
183
+ timelimit = config_cycle_slow_time_perc * 1000000 /server .hz /100 ;
165
184
timelimit_exit = 0 ;
166
185
if (timelimit <= 0 ) timelimit = 1 ;
167
186
168
187
if (type == ACTIVE_EXPIRE_CYCLE_FAST )
169
- timelimit = ACTIVE_EXPIRE_CYCLE_FAST_DURATION ; /* in microseconds. */
188
+ timelimit = config_cycle_fast_duration ; /* in microseconds. */
170
189
171
190
/* Accumulate some global stats as we expire keys, to have some idea
172
191
* about the number of keys that are already logically expired, but still
@@ -214,8 +233,8 @@ void activeExpireCycle(int type) {
214
233
ttl_sum = 0 ;
215
234
ttl_samples = 0 ;
216
235
217
- if (num > ACTIVE_EXPIRE_CYCLE_KEYS_PER_LOOP )
218
- num = ACTIVE_EXPIRE_CYCLE_KEYS_PER_LOOP ;
236
+ if (num > config_keys_per_loop )
237
+ num = config_keys_per_loop ;
219
238
220
239
/* Here we access the low level representation of the hash table
221
240
* for speed concerns: this makes this code coupled with dict.c,
@@ -277,7 +296,7 @@ void activeExpireCycle(int type) {
277
296
/* We don't repeat the cycle for the current database if there are
278
297
* an acceptable amount of stale keys (logically expired but yet
279
298
* not reclained). */
280
- } while ((expired * 100 /sampled ) > ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE );
299
+ } while ((expired * 100 /sampled ) > config_cycle_acceptable_stale );
281
300
}
282
301
283
302
elapsed = ustime ()- start ;
0 commit comments