Top Redis Headaches for DevOps: Replication Timeouts
Join the DZone community and get the full member experience.Join For Free
redis provides a wide variety of tools directed at improving and maintaining efficient in-memory database usage. while its unique data types and commands fine-tune databases to serve application requests without any additional processing at the application level, misconfiguration, or rather, using out-of-the-box configuration, can (and does) lead to operational challenges and performance issues. despite the setbacks that have been the cause of quite a few headaches, solutions do exist, and may be even simpler than anticipated. this series of installments will highlight some of the most irritating issues that come up when using redis, along with tips on how to solve them. they are based on our real-life experience of running thousands of redis database instances.
following our previous installment in the series, the replication buffer , the next headache on our list will carry on with the topic of master-slave replication. in particular, we will look a bit deeper at the length of time needed to complete the process as well as some configuration issues that can cause major inconveniences.
as we've previously discussed in the endless replication loop post , redis' replication process is made up of two synchronization stages: initial and ongoing. while the ongoing stage is fairly stable (as long as the link between the master and slave is kept), the initial phase is somewhat trickier to complete. successful completion of the initial synchronization is dependent not only on the amount of memory that's allocated for the replication buffer (see previous headache ) but also on the amount of time that this step takes.
you may recall that the initial synchronization step consists of a background save and the transmission of the entire database from the master to the slave. depending on the dataset's size and the quality of the network connection, this may prove to be a lengthy process to complete. if that phase takes too long, redis' replication timeout setting may be reached, thus causing the initial phase to be repeated over and over, ad nauseam. in such cases, you will find your slave's redis log riddled with messages such as:
 21 jul 00:33:36.031 * connecting to master 10.60.228.106:25994  21 jul 00:33:36.032 * master <-> slave sync started  21 jul 00:33:36.032 * non blocking connect for sync fired the event.  21 jul 00:33:36.032 * master replied to ping, replication can continue...  21 jul 00:33:36.032 * partial resynchronization not possible (no cached master)  21 jul 00:33:36.032 * full resync from master: 549907b03661629665eb90846ea921f23de6c961:2537453
redis' replication timeout is set to 60 seconds by default (see the repl-timeout directive in your redis.conf file or do a config get repl-timeout using redis-cli). this period of time may be far too short, especially when you have:
slow storage: if the master and/or the slave are attached to a slow-performing storage, this will cause the background saving process to take a significant amount of time in the master's case. in slave's case, writing and loading the data from disk may be prolonged.
big dataset: the bigger the dataset's size is, the more time it will require time to save and transfer.
network performance: when network link between the master and slave has limited bandwidth and/or high latency, it directly affects the rate of data transfer.
you can rectify this by setting the replication timeout to a more appropriate value. start by working on an acceptable estimate of the time needed to replicate the database. first, check how long it takes redis to perform a background save by executing the bgsave command and examining the log file for the relevant lines (i.e. * background saving started by pid nnn * indicates that the process started, whereas * background saving terminated with success * indicates its termination). next, time how long it takes you to copy the resulting rdb file from the master to the slave's disk. lastly, you'll need to time how long it takes to actually load the data from disk (e.g. by restarting redis and looking for the * db loaded from disk line in the log file). the sum of these measurements can serve as a rough estimate of your desired replication timeout value, but you'd probably want to add 10-20% to it for safety.
once you've set up the timeout based on the estimate, you can test how long replication actually takes by having the slave do a full synchronization a few times and examining the log file. if possible, try repeating this exercise at different times throughout the day to better gauge the system's behavior under different loads. lastly, keep in mind that the timeout setting's value should be reviewed periodically based on your database's growth.
this concludes our review of redis' replication headaches. replication is a powerful tool for keeping your database available and scaling its read throughput, but mind the default settings and make sure you've configured the database to your use case.
if you've finished reading this article and want to dive into the next common cause for devops' headaches then continue reading about the client buffers .- see more at: http://redislabs.com/blog/top-redis-headaches-for-devops-replication-timeouts#.u-tw4ejemae
Published at DZone with permission of Itamar Haber, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.