Please enable JavaScript.
Coggle requires JavaScript to display documents.
Redis In Action (Data Structures p34 (String (Integer value (can…
Redis In Action
-
-
-
-
-
not widely used because
- system reliability - in older version, slow consuming causes buffer out-grown and may crash the system,
in newer versions, subers are disconnected when buffer reached limit
- data transmission reliability - if the client is disconnected and a msg is sent before it reconnect, the message is LOST
WATCH
like CAS, if watched keys are modified when calling EXEC, fail the transaction
-
EXEC
-
Redis send MULTI, commands, EXEC all at the same time.
Delayed execution with MULTI / EXEC can improve performance and reduce network round trip time
-
-
-
-
commands
save 60 1000
(automatically call BGSAVE if 1000 writes occerred within 60 seconds since the last successful save has started)
-
-
-
-
upon SHUTDOWN command / SIGTERM signal, Redis perform a SAVE (blocking any further client commands) and then shutdown
-
:!: when using 10s of GB memory, BGSAVE can cause system to pause for extended periods of time, or heavy use of virtual memory, degrading Redis performance
Append-Only File
-
-
File Syncing
first, write data to buffer, then OS take the data and write to disk in the future, optionally call file.flush() to request OS write buffered data to disk asap
:!: appendfsync always causes frequent appending small data to end of file, which will cause write amplification and reduce the lifetime of SSD significantly in some cases
-
:!: will cause large backup file size, and upon restart Redis executes all commands in the AOF, can take long time to start up
rewriting/compacting AOF p97
BGREWRITEAOF
-
same(worse) impact as snapshotting, fork time, memory usage, system pausing long time while deleting old AOF file
-
-
one master server handles write request, sends copy of the data to other follower servers, and let these followers handle read requests
when a follower connects to the master, the master starts a BGSAVE operation
SLAVEOF host port
in configuration file or command, run in slave mode and use the given address as the master
- slave connects to the master and issues the SYNC command
- master starts BGSAVE and keeps a backlog of all write commands received after BGSAVE, slave serves old data it has for the moment
- master finishes BGSAVE, start sending the snapshot to slave and keep backlogging new writes, slave discards all old data and load the snapshot from master
- finishes sending the snapshot to the slave, start sending the write command backlog to the slave, slave start responding read requests when finished loading snapshot
- master finished sending backlog, resume handling write requests, slave executes backlog and handle read requests after that
:!:when a slave initially connects to master, all data in slave's memory will be lost, to be replaced by the data coming from the master
-
if a slave X has its own slave Y, and X is in step 4, X will disconnect Y, causing Y to reconnect and resync
:star: good practice to have Redis master use only 50%-65% memory in the system, leaving 30-45% for spare memory during BGSAVE and command backlog
Verify disk writes
check output of INFO command for aof_pending_bio_fsync, will be 0 if all data the server knows about has been written to disk
Verify snapshots and AOF
redis-check-aof --fix
scans thru the AOF looking for incorrect command. Upon finding the first bad command,
trim the file to just before that bad command would've been executed. (may discard commands after the first bad command)
redis-check-dump
NO way to repair a corrupted snapshot. Better keep multiple backups of important snapshots,
and calculate SHA1 / SHA256 hashes to verify content during restoration. (Redis >= 2.6 includes CRC64 checksum as part of snapshot)
:star: BUT, CRC checksum is useful for network transfer / disk corruption, SHA checksum is much better suited for discovering arbitrary errors
Replacing failed master p105
A. call SAVE on a slave to produce a snapshot, copy that to the new master node and start the node, then make the slave node point to the new master
B. turn the slave into a master, and create a new slave