|
| 1 | ++++ |
| 2 | +title = 'Warm Restart' |
| 3 | +date = 2024-09-04T13:57:33-07:00 |
| 4 | ++++ |
| 5 | + |
| 6 | +Memcached 1.5.18 and newer can recover its cache between clean restarts. It can restart after upgrades of the |
| 7 | +binary, most changes in settings, and so on. It now also supports |
| 8 | +using persistent memory via DAX filesystem mounts. See below for more details. |
| 9 | + |
| 10 | +Use it by adding: `-e /tmpfs_mount/memory_file` to your startup options. |
| 11 | + |
| 12 | +`/tmpfs_mount/` must be a ram disk of some sort, big enough to satisfy the |
| 13 | +memory limit specified on startup with `-m`. To gracefully restart; send a |
| 14 | +SIGUSR1 signal to the daemon, and wait for it to shut down and exit. |
| 15 | + |
| 16 | +It will create a `/tmpfs_mount/memory_file.meta` file on shutdown. On restart |
| 17 | +it will read this file and ensure the restart is compatible. If it is not |
| 18 | +compatible or the file is corrupt, it will start with a clean cache. |
| 19 | + |
| 20 | +If you change some parameters the cache will come up clean: |
| 21 | + |
| 22 | +- The memory limit (`-m`) |
| 23 | +- The max item size. |
| 24 | +- Slab chunk sizes. |
| 25 | +- Whether CAS is enabled or not. |
| 26 | +- Whether slab reassignment is allowed or not. |
| 27 | + |
| 28 | +... you are able to change all other options inbetween restarts! |
| 29 | + |
| 30 | +Important Caveats (see below for more detail): |
| 31 | + |
| 32 | +- System clock must be set correctly and must not jump while memcached |
| 33 | + is down. |
| 34 | +- Deletes, sets, adds, incr/decr/etc commands will be missed while instance |
| 35 | + restarts! |
| 36 | +- The earliest version you can restart from is 1.5.18. Older versions cannot |
| 37 | + upgrade to 1.5.18 without losing the cache. |
| 38 | + |
| 39 | +## DETAILS |
| 40 | + |
| 41 | +This works by putting memory related to item data into an external |
| 42 | +mmap file (specified via `-e`). All other memory: the hash table, connection |
| 43 | +memory, etc, stay in main RAM. When the daemon is restarted, it runs a pass |
| 44 | +over the item data and fixes up the internal pointers and regenerates |
| 45 | +the hash table. This typically takes a few seconds, but if you have close to a |
| 46 | +billion items in memory it can take two or three minutes. |
| 47 | + |
| 48 | +Once restarted, there is no performance difference between restartable and |
| 49 | +non-restartable modes. |
| 50 | + |
| 51 | +### DAX mounts and persistent memory |
| 52 | + |
| 53 | +If you have a persistent memory device, you can utilize this feature to extend |
| 54 | +memcached's memory into persistent memory. This does _not_ make |
| 55 | +memcached crash safe! It will put item memory into your persistent memory |
| 56 | +mount, while the rest of memory (hash table/buffers/etc) use system DRAM. This |
| 57 | +is a very high performance mode as the majority of memory accesses stay in DRAM. Also, with a graceful shutdown memcached can be |
| 58 | +restarted after reboots so long as the DAX mount persists. |
| 59 | + |
| 60 | +See your persistent memory vendor's documentation for how to configure a DAX |
| 61 | +mount. |
| 62 | + |
| 63 | +You can see extensive testing we did in this and other modes on our blog: https://memcached.org/blog/persistent-memory/ |
| 64 | + |
| 65 | +### CAVEATS |
| 66 | + |
| 67 | +Your system clock _must_ be set correctly, or at least it must not move before |
| 68 | +memcached has restarted. The only way to tell how much time has passed while |
| 69 | +the binary was dead, is to check the system clock. If the clock jumps forward |
| 70 | +or backwards it could impact items with a specific TTL. |
| 71 | + |
| 72 | +Users must keep in mind that while an instance is stopped, it may be missing |
| 73 | +updates from the network; deletes, sets, and so on. It is only safe to restart |
| 74 | +memcached if your architecture can handle this by either pausing/buffering |
| 75 | +updates, or restarting at a time when no changes are happening to the cache. |
| 76 | + |
| 77 | +### FUTURE WORK |
| 78 | + |
| 79 | +This feature is presently incompatible with extstore. Please let us know if |
| 80 | +you have other feedback or requests related to this feature. |
| 81 | + |
0 commit comments