Skip to content

Commit 02bb515

Browse files
committed
Config: Add quicklist, remove old list options
This removes: - list-max-ziplist-entries - list-max-ziplist-value This adds: - list-max-ziplist-size - list-compress-depth Also updates config file with new sections and updates tests to use quicklist settings instead of old list settings.
1 parent bbbbfb1 commit 02bb515

File tree

10 files changed

+72
-41
lines changed

10 files changed

+72
-41
lines changed

redis.conf

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,36 @@ notify-keyspace-events ""
818818
hash-max-ziplist-entries 512
819819
hash-max-ziplist-value 64
820820

821-
# Similarly to hashes, small lists are also encoded in a special way in order
822-
# to save a lot of space. The special representation is only used when
823-
# you are under the following limits:
824-
list-max-ziplist-entries 512
825-
list-max-ziplist-value 64
821+
# Lists are also encoded in a special way to save a lot of space.
822+
# The number of entries allowed per internal list node can be specified
823+
# as a fixed maximum size or a maximum number of elements.
824+
# For a fixed maximum size, use -5 through -1, meaning:
825+
# -5: max size: 64 Kb <-- not recommended for normal workloads
826+
# -4: max size: 32 Kb <-- not recommended
827+
# -3: max size: 16 Kb <-- probably not recommended
828+
# -2: max size: 8 Kb <-- good
829+
# -1: max size: 4 Kb <-- good
830+
# Positive numbers mean store up to _exactly_ that number of elements
831+
# per list node.
832+
# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),
833+
# but if your use case is unique, adjust the settings as necessary.
834+
list-max-ziplist-size -2
835+
836+
# Lists may also be compressed.
837+
# Compress depth is the number of quicklist ziplist nodes from *each* side of
838+
# the list to *exclude* from compression. The head and tail of the list
839+
# are always uncompressed for fast push/pop operations. Settings are:
840+
# 0: disable all list compression
841+
# 1: depth 1 means "don't start compressing until after 1 node into the list,
842+
# going from either the head or tail"
843+
# So: [head]->node->node->...->node->[tail]
844+
# [head], [tail] will always be uncompressed; inner nodes will compress.
845+
# 2: [head]->[next]->node->node->...->node->[prev]->[tail]
846+
# 2 here means: don't compress head or head->next or tail->prev or tail,
847+
# but compress all nodes between them.
848+
# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]
849+
# etc.
850+
list-compress-depth 0
826851

827852
# Sets have a special encoding in just one case: when a set is composed
828853
# of just strings that happen to be integers in radix 10 in the range

src/config.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,13 @@ void loadServerConfigFromString(char *config) {
397397
} else if (!strcasecmp(argv[0],"hash-max-ziplist-value") && argc == 2) {
398398
server.hash_max_ziplist_value = memtoll(argv[1], NULL);
399399
} else if (!strcasecmp(argv[0],"list-max-ziplist-entries") && argc == 2){
400-
server.list_max_ziplist_entries = memtoll(argv[1], NULL);
400+
/* DEAD OPTION */
401401
} else if (!strcasecmp(argv[0],"list-max-ziplist-value") && argc == 2) {
402-
server.list_max_ziplist_value = memtoll(argv[1], NULL);
402+
/* DEAD OPTION */
403+
} else if (!strcasecmp(argv[0],"list-max-ziplist-size") && argc == 2) {
404+
server.list_max_ziplist_size = atoi(argv[1]);
405+
} else if (!strcasecmp(argv[0],"list-compress-depth") && argc == 2) {
406+
server.list_compress_depth = atoi(argv[1]);
403407
} else if (!strcasecmp(argv[0],"set-max-intset-entries") && argc == 2) {
404408
server.set_max_intset_entries = memtoll(argv[1], NULL);
405409
} else if (!strcasecmp(argv[0],"zset-max-ziplist-entries") && argc == 2) {
@@ -795,12 +799,12 @@ void configSetCommand(redisClient *c) {
795799
} else if (!strcasecmp(c->argv[2]->ptr,"hash-max-ziplist-value")) {
796800
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt;
797801
server.hash_max_ziplist_value = ll;
798-
} else if (!strcasecmp(c->argv[2]->ptr,"list-max-ziplist-entries")) {
802+
} else if (!strcasecmp(c->argv[2]->ptr,"list-max-ziplist-size")) {
799803
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt;
800-
server.list_max_ziplist_entries = ll;
801-
} else if (!strcasecmp(c->argv[2]->ptr,"list-max-ziplist-value")) {
804+
server.list_max_ziplist_size = ll;
805+
} else if (!strcasecmp(c->argv[2]->ptr,"list-compress-depth")) {
802806
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt;
803-
server.list_max_ziplist_value = ll;
807+
server.list_compress_depth = ll;
804808
} else if (!strcasecmp(c->argv[2]->ptr,"set-max-intset-entries")) {
805809
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt;
806810
server.set_max_intset_entries = ll;
@@ -1047,10 +1051,10 @@ void configGetCommand(redisClient *c) {
10471051
server.hash_max_ziplist_entries);
10481052
config_get_numerical_field("hash-max-ziplist-value",
10491053
server.hash_max_ziplist_value);
1050-
config_get_numerical_field("list-max-ziplist-entries",
1051-
server.list_max_ziplist_entries);
1052-
config_get_numerical_field("list-max-ziplist-value",
1053-
server.list_max_ziplist_value);
1054+
config_get_numerical_field("list-max-ziplist-size",
1055+
server.list_max_ziplist_size);
1056+
config_get_numerical_field("list-compress-depth",
1057+
server.list_compress_depth);
10541058
config_get_numerical_field("set-max-intset-entries",
10551059
server.set_max_intset_entries);
10561060
config_get_numerical_field("zset-max-ziplist-entries",
@@ -1857,8 +1861,8 @@ int rewriteConfig(char *path) {
18571861
rewriteConfigNotifykeyspaceeventsOption(state);
18581862
rewriteConfigNumericalOption(state,"hash-max-ziplist-entries",server.hash_max_ziplist_entries,REDIS_HASH_MAX_ZIPLIST_ENTRIES);
18591863
rewriteConfigNumericalOption(state,"hash-max-ziplist-value",server.hash_max_ziplist_value,REDIS_HASH_MAX_ZIPLIST_VALUE);
1860-
rewriteConfigNumericalOption(state,"list-max-ziplist-entries",server.list_max_ziplist_entries,REDIS_LIST_MAX_ZIPLIST_ENTRIES);
1861-
rewriteConfigNumericalOption(state,"list-max-ziplist-value",server.list_max_ziplist_value,REDIS_LIST_MAX_ZIPLIST_VALUE);
1864+
rewriteConfigNumericalOption(state,"list-max-ziplist-size",server.list_max_ziplist_size,REDIS_LIST_MAX_ZIPLIST_SIZE);
1865+
rewriteConfigNumericalOption(state,"list-compress-depth",server.list_compress_depth,REDIS_LIST_COMPRESS_DEPTH);
18621866
rewriteConfigNumericalOption(state,"set-max-intset-entries",server.set_max_intset_entries,REDIS_SET_MAX_INTSET_ENTRIES);
18631867
rewriteConfigNumericalOption(state,"zset-max-ziplist-entries",server.zset_max_ziplist_entries,REDIS_ZSET_MAX_ZIPLIST_ENTRIES);
18641868
rewriteConfigNumericalOption(state,"zset-max-ziplist-value",server.zset_max_ziplist_value,REDIS_ZSET_MAX_ZIPLIST_VALUE);

src/rdb.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,15 +835,15 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
835835
if ((len = rdbLoadLen(rdb,NULL)) == REDIS_RDB_LENERR) return NULL;
836836

837837
o = createQuicklistObject();
838-
quicklistSetFill(o->ptr, server.list_max_ziplist_entries);
839-
quicklistSetCompress(o->ptr, 0 /*FIXME*/);
838+
quicklistSetOptions(o->ptr, server.list_max_ziplist_size,
839+
server.list_compress_depth);
840840

841841
/* Load every single element of the list */
842842
while(len--) {
843843
if ((ele = rdbLoadEncodedStringObject(rdb)) == NULL) return NULL;
844844
dec = getDecodedObject(ele);
845845
size_t len = sdslen(dec->ptr);
846-
o->ptr = quicklistPushTail(o->ptr, dec->ptr, len);
846+
quicklistPushTail(o->ptr, dec->ptr, len);
847847
decrRefCount(dec);
848848
decrRefCount(ele);
849849
}
@@ -985,6 +985,8 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
985985
} else if (rdbtype == REDIS_RDB_TYPE_LIST_QUICKLIST) {
986986
if ((len = rdbLoadLen(rdb,NULL)) == REDIS_RDB_LENERR) return NULL;
987987
o = createQuicklistObject();
988+
quicklistSetOptions(o->ptr, server.list_max_ziplist_size,
989+
server.list_compress_depth);
988990

989991
while (len--) {
990992
if ((ele = rdbLoadStringObject(rdb)) == NULL) return NULL;

src/redis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,8 @@ void initServerConfig(void) {
14491449
server.maxmemory_samples = REDIS_DEFAULT_MAXMEMORY_SAMPLES;
14501450
server.hash_max_ziplist_entries = REDIS_HASH_MAX_ZIPLIST_ENTRIES;
14511451
server.hash_max_ziplist_value = REDIS_HASH_MAX_ZIPLIST_VALUE;
1452-
server.list_max_ziplist_entries = REDIS_LIST_MAX_ZIPLIST_ENTRIES;
1453-
server.list_max_ziplist_value = REDIS_LIST_MAX_ZIPLIST_VALUE;
1452+
server.list_max_ziplist_size = REDIS_LIST_MAX_ZIPLIST_SIZE;
1453+
server.list_compress_depth = REDIS_LIST_COMPRESS_DEPTH;
14541454
server.set_max_intset_entries = REDIS_SET_MAX_INTSET_ENTRIES;
14551455
server.zset_max_ziplist_entries = REDIS_ZSET_MAX_ZIPLIST_ENTRIES;
14561456
server.zset_max_ziplist_value = REDIS_ZSET_MAX_ZIPLIST_VALUE;

src/redis.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,14 @@ typedef long long mstime_t; /* millisecond time type. */
331331
/* Zip structure related defaults */
332332
#define REDIS_HASH_MAX_ZIPLIST_ENTRIES 512
333333
#define REDIS_HASH_MAX_ZIPLIST_VALUE 64
334-
#define REDIS_LIST_MAX_ZIPLIST_ENTRIES 512
335-
#define REDIS_LIST_MAX_ZIPLIST_VALUE 64
336334
#define REDIS_SET_MAX_INTSET_ENTRIES 512
337335
#define REDIS_ZSET_MAX_ZIPLIST_ENTRIES 128
338336
#define REDIS_ZSET_MAX_ZIPLIST_VALUE 64
339337

338+
/* List defaults */
339+
#define REDIS_LIST_MAX_ZIPLIST_SIZE -2
340+
#define REDIS_LIST_COMPRESS_DEPTH 0
341+
340342
/* HyperLogLog defines */
341343
#define REDIS_DEFAULT_HLL_SPARSE_MAX_BYTES 3000
342344

@@ -871,12 +873,14 @@ struct redisServer {
871873
/* Zip structure config, see redis.conf for more information */
872874
size_t hash_max_ziplist_entries;
873875
size_t hash_max_ziplist_value;
874-
size_t list_max_ziplist_entries;
875-
size_t list_max_ziplist_value;
876876
size_t set_max_intset_entries;
877877
size_t zset_max_ziplist_entries;
878878
size_t zset_max_ziplist_value;
879879
size_t hll_sparse_max_bytes;
880+
/* List parameters */
881+
int list_max_ziplist_size;
882+
int list_compress_depth;
883+
/* time cache */
880884
time_t unixtime; /* Unix time sampled every cron cycle. */
881885
long long mstime; /* Like 'unixtime' but with milliseconds resolution. */
882886
/* Pubsub */

src/t_list.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ void listTypeConvert(robj *subject, int enc) {
181181
redisAssertWithInfo(NULL,subject,subject->encoding==REDIS_ENCODING_ZIPLIST);
182182

183183
if (enc == REDIS_ENCODING_QUICKLIST) {
184-
size_t zlen = server.list_max_ziplist_entries;
185-
184+
size_t zlen = server.list_max_ziplist_size;
185+
int depth = server.list_compress_depth;
186+
subject->ptr = quicklistCreateFromZiplist(zlen, depth, subject->ptr);
186187
subject->encoding = REDIS_ENCODING_QUICKLIST;
187-
subject->ptr = quicklistCreateFromZiplist(zlen, 0 /*FIXME*/, subject->ptr);
188188
} else {
189189
redisPanic("Unsupported list conversion");
190190
}
@@ -207,8 +207,8 @@ void pushGenericCommand(redisClient *c, int where) {
207207
c->argv[j] = tryObjectEncoding(c->argv[j]);
208208
if (!lobj) {
209209
lobj = createQuicklistObject();
210-
quicklistSetFill(lobj->ptr, server.list_max_ziplist_entries);
211-
quicklistSetCompress(lobj->ptr, 0 /*FIXME*/);
210+
quicklistSetOptions(lobj->ptr, server.list_max_ziplist_size,
211+
server.list_compress_depth);
212212
dbAdd(c->db,c->argv[1],lobj);
213213
}
214214
listTypePush(lobj,c->argv[j],where);
@@ -537,8 +537,8 @@ void rpoplpushHandlePush(redisClient *c, robj *dstkey, robj *dstobj, robj *value
537537
/* Create the list if the key does not exist */
538538
if (!dstobj) {
539539
dstobj = createQuicklistObject();
540-
quicklistSetFill(dstobj->ptr, server.list_max_ziplist_entries);
541-
quicklistSetCompress(dstobj->ptr, 0 /*FIXME*/);
540+
quicklistSetOptions(dstobj->ptr, server.list_max_ziplist_size,
541+
server.list_compress_depth);
542542
dbAdd(c->db,dstkey,dstobj);
543543
}
544544
signalModifiedKey(c->db,dstkey);

tests/unit/sort.tcl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
start_server {
22
tags {"sort"}
33
overrides {
4-
"list-max-ziplist-value" 16
5-
"list-max-ziplist-entries" 32
4+
"list-max-ziplist-size" 32
65
"set-max-intset-entries" 32
76
}
87
} {

tests/unit/type/list-2.tcl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
start_server {
22
tags {"list"}
33
overrides {
4-
"list-max-ziplist-value" 16
5-
"list-max-ziplist-entries" 4
4+
"list-max-ziplist-size" 4
65
}
76
} {
87
source "tests/unit/type/list-common.tcl"

tests/unit/type/list-3.tcl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
start_server {
22
tags {list ziplist}
33
overrides {
4-
"list-max-ziplist-value" 200000
5-
"list-max-ziplist-entries" 16
4+
"list-max-ziplist-size" 16
65
}
76
} {
87
test {Explicit regression for a list bug} {

tests/unit/type/list.tcl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
start_server {
22
tags {"list"}
33
overrides {
4-
"list-max-ziplist-value" 16
5-
"list-max-ziplist-entries" 5
4+
"list-max-ziplist-size" 5
65
}
76
} {
87
source "tests/unit/type/list-common.tcl"

0 commit comments

Comments
 (0)