How Memcached Works
Posted on January 13, 2020 (Last modified on June 20, 2022) • 4 min read • 757 wordsThis article discuss memcached internals
From memcached.org:
Memcached is Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
-m
) option. In ElastiCache this was configured using max_cache_memory
parameter in parameter group. Value of max_cache_memory
parameter cannot be changed. This is not directly requested to operating systems when memcached start but will be requested as needed.Below table is reference of Memcached slab classes with its chunk size using default settings (default parameter group)
Slab Class | Chunk Size (bytes) | Chunks Per Page | Usable space per chunk |
---|---|---|---|
1 | 96 | 10922 | 48 |
2 | 120 | 8738 | 72 |
3 | 152 | 6898 | 104 |
4 | 192 | 5461 | 144 |
5 | 240 | 4369 | 192 |
6 | 304 | 3449 | 256 |
7 | 384 | 2730 | 336 |
8 | 480 | 2184 | 432 |
9 | 600 | 1747 | 552 |
10 | 752 | 1394 | 704 |
11 | 944 | 1110 | 896 |
12 | 1184 | 885 | 1136 |
13 | 1480 | 708 | 1432 |
14 | 1856 | 564 | 1808 |
15 | 2320 | 451 | 2272 |
16 | 2904 | 361 | 2856 |
17 | 3632 | 288 | 3584 |
18 | 4544 | 230 | 4496 |
19 | 5680 | 184 | 5632 |
20 | 7104 | 147 | 7056 |
21 | 8880 | 118 | 8832 |
22 | 11104 | 94 | 11056 |
23 | 13880 | 75 | 13832 |
24 | 17352 | 60 | 17304 |
25 | 21696 | 48 | 21648 |
26 | 27120 | 38 | 27072 |
27 | 33904 | 30 | 33856 |
28 | 42384 | 24 | 42336 |
29 | 52984 | 19 | 52936 |
30 | 66232 | 15 | 66184 |
31 | 82792 | 12 | 82744 |
32 | 103496 | 10 | 103448 |
33 | 129376 | 8 | 129328 |
34 | 161720 | 6 | 161672 |
35 | 202152 | 5 | 202104 |
36 | 252696 | 4 | 252648 |
37 | 315872 | 3 | 315824 |
38 | 394840 | 2 | 394792 |
39 | 524288 | 2 | 524240 |
Chunk Size = 48 bytes metadata