@@ -9,9 +9,7 @@ categories:
99- oss
1010- kubernetes
1111- clients
12- description : ' Debugging memory consumption
13-
14- '
12+ description : Debugging memory consumption
1513linkTitle : Memory Usage
1614title : Redis JSON RAM Usage
1715weight : 6
@@ -22,15 +20,15 @@ well as some per-key overhead that Redis uses. On top of that, the value in the
2220RAM.
2321
2422Redis JSON stores JSON values as binary data after deserializing them. This representation is often more
25- expensive, size-wise, than the serialized form. The JSON data type uses at least 24 bytes (on
23+ expensive, size-wise, than the serialized form. The JSON data type uses at least 8 bytes (on
262464-bit architectures) for every value, as can be seen by sampling an empty string with the
2725[ ` JSON.DEBUG MEMORY ` ] ({{< relref "commands/json.debug-memory/" >}}) command:
2826
2927```
3028127.0.0.1:6379> JSON.SET emptystring . '""'
3129OK
3230127.0.0.1:6379> JSON.DEBUG MEMORY emptystring
33- (integer) 24
31+ (integer) 8
3432```
3533
3634This RAM requirement is the same for all scalar values, but strings require additional space
@@ -40,20 +38,20 @@ depending on their actual length. For example, a 3-character string will use 3 a
4038127.0.0.1:6379> JSON.SET foo . '"bar"'
4139OK
4240127.0.0.1:6379> JSON.DEBUG MEMORY foo
43- (integer) 27
41+ (integer) 11
4442```
4543
46- Empty containers take up 32 bytes to set up:
44+ Empty containers take up 8 bytes to set up:
4745
4846```
4947127.0.0.1:6379> JSON.SET arr . '[]'
5048OK
5149127.0.0.1:6379> JSON.DEBUG MEMORY arr
52- (integer) 32
50+ (integer) 8
5351127.0.0.1:6379> JSON.SET obj . '{}'
5452OK
5553127.0.0.1:6379> JSON.DEBUG MEMORY obj
56- (integer) 32
54+ (integer) 8
5755```
5856
5957The actual size of a container is the sum of sizes of all items in it on top of its own
@@ -65,7 +63,7 @@ A container with a single scalar is made up of 32 and 24 bytes, respectively:
6563127.0.0.1:6379> JSON.SET arr . '[""]'
6664OK
6765127.0.0.1:6379> JSON.DEBUG MEMORY arr
68- (integer) 56
66+ (integer) 64
6967```
7068
7169A container with two scalars requires 40 bytes for the container (each pointer to an entry in the
@@ -74,7 +72,7 @@ container is 8 bytes), and 2 * 24 bytes for the values themselves:
7472127.0.0.1:6379> JSON.SET arr . '["", ""]'
7573OK
7674127.0.0.1:6379> JSON.DEBUG MEMORY arr
77- (integer) 88
75+ (integer) 72
7876```
7977
8078A 3-item (each 24 bytes) container will be allocated with capacity for 4 items, i.e. 56 bytes:
@@ -83,7 +81,7 @@ A 3-item (each 24 bytes) container will be allocated with capacity for 4 items,
8381127.0.0.1:6379> JSON.SET arr . '["", "", ""]'
8482OK
8583127.0.0.1:6379> JSON.DEBUG MEMORY arr
86- (integer) 128
84+ (integer) 80
8785```
8886
8987The next item will not require an allocation in the container, so usage will increase only by that
@@ -93,24 +91,23 @@ scalar's requirement, but another value will scale the container again:
9391127.0.0.1:6379> JSON.SET arr . '["", "", "", ""]'
9492OK
9593127.0.0.1:6379> JSON.DEBUG MEMORY arr
96- (integer) 152
94+ (integer) 88
9795127.0.0.1:6379> JSON.SET arr . '["", "", "", "", ""]'
9896OK
9997127.0.0.1:6379> JSON.DEBUG MEMORY arr
100- (integer) 208
98+ (integer) 128
10199```
102100
103- This table gives the size (in bytes) of a few of the test files on disk and when stored using
104- JSON. The _ MessagePack_ column is for reference purposes and reflects the length of the value
105- when stored using MessagePack.
106-
107- | File | Filesize | Redis JSON | MessagePack |
108- | -------------------------------------- | --------- | ------ | ----------- |
109- | /tests/files/pass-100.json | 380 | 1079 | 140 |
110- | /tests/files/pass-jsonsl-1.json | 1441 | 3666 | 753 |
111- | /tests/files/pass-json-parser-0000.json | 3468 | 7209 | 2393 |
112- | /tests/files/pass-jsonsl-yahoo2.json | 18446 | 37469 | 16869 |
113- | /tests/files/pass-jsonsl-yelp.json | 39491 | 75341 | 35469 |
101+ This table gives the size (in bytes) of a few of the test files from the [ module repo] ( https://github.com/RedisJSON/RedisJSON ) , stored using
102+ JSON. The _ MessagePack_ column is for reference purposes and reflects the length of the value when stored using [ MessagePack] ( https://msgpack.org/index.html ) .
103+
104+ | File | File size | Redis JSON | MessagePack |
105+ | --------------------------------------- | --------- | ---------- | ----------- |
106+ | /tests/files/pass-100.json | 381 | 1349 | 140 |
107+ | /tests/files/pass-jsonsl-1.json | 1387 | 2734 | 757 |
108+ | /tests/files/pass-json-parser-0000.json | 3718 | 6157 | 2393 |
109+ | /tests/files/pass-jsonsl-yahoo2.json | 22466 | 29957 | 16869 |
110+ | /tests/files/pass-jsonsl-yelp.json | 46333 | 63489 | 35529 |
114111
115112> Note: In the current version, deleting values from containers ** does not** free the container's
116113 allocated memory.
0 commit comments