Bobcares

Redis Latency Monitoring – Enable it with ease

by | Dec 21, 2020

Redis Latency Monitoring helps the user to check and troubleshoot possible latency problems.

As part of our Server Management Services, we assist our customers with several Redis queries

Today, let us discuss latency monitoring and how it relates to Redis.

 

Redis Latency Monitoring

Redis is often used in the context of demanding use cases. It serves a large number of queries per second per instance. At the same time, there are very strict latency requirements. For the average response time as well as the worst-case latency.

While Redis is an in-memory system, it deals with the operating system in different ways. For instance, in the context of persisting to disk.

Moreover, Redis implements a rich set of commands. Certain commands are fast and run in constant or logarithmic time, while others are slower and can cause latency spikes.

Finally, Redis is single-threaded. This is usually an advantage from the point of view of the amount of work it can perform per core. In the latency figures, it is able to provide. However, it poses a challenge in latency since the single thread must be able to perform certain tasks incrementally. For example, key expiration.

For all these reasons, Redis 2.8.13 introduced Latency Monitoring. It helps the user to check and troubleshoot possible latency problems.

Latency monitoring is of the following conceptual parts:

  • Latency hooks that sample different latency sensitive code paths.
  • Time series recording of latency spikes split by a different event.
  • Reporting engine to fetch raw data from the time series.
  • Analysis engine to provide human-readable reports and hints according to the measurements.

Redis Latency Monitoring

Events and time series

Different monitor code paths have different names called events. For example, a command is an event measuring latency spikes of possibly slow command executions. However, fast-command is the event name for the monitoring of the O(1) and O(log N) commands.

Other events are less generic and monitor a very specific operation by Redis. For example, the fork event only monitors the time taken by Redis to execute the fork(2) system call.

A latency spike is an event that runs in more time than the configured latency threshold. A separate time series associate with every monitored event.

This is how the time series work:

  • Every time a latency spike happens, it logs in the appropriate time series.
  • Every time series compose 160 elements.
  • Each element is a pair: a Unix timestamp of the time the latency spike was measured, and the number of milliseconds the event took to execute.
  • Latency spikes for the same event happening in the same second will merge. So even if continuous latency spikes measure for a given event, at least 180 seconds of history are available.
  • For every element, the all-time maximum latency will record.

The framework monitors and logs latency spikes in the execution time of these events:

command: regular commands.

fast-command: O(1) and O(log N) commands.

fork: the fork(2) system call.

rdb-unlink-temp-file: the unlink(2) system call.

aof-write: writing to the AOF – a catchall event fsync(2) system calls.

aof-fsync-always: the fsync(2) system call when invoked by the appendfsync allways policy.

aof-write-pending-fsync: the fsync(2) system call when there are pending writes.

aof-write-active-child: the fsync(2) system call when performed by a child process.

aof-write-alone: the fsync(2) system call when performed by the main process.

aof-fstat: the fstat(2) system call.

aof-rename: the rename(2) system call for renaming the temporary file after completing BGREWRITEAOF.

aof-rewrite-diff-write: writing the differences accumulated while performing BGREWRITEAOF.

active-defrag-cycle: the active defragmentation cycle.

expire-cycle: the expiration cycle.

eviction-cycle: the eviction cycle.

eviction-del: deletes during the eviction cycle.

 

How to enable latency monitoring

There are applications where all the queries must serve in less than 1 millisecond. And applications where time to time a small percentage of clients experiencing a 2-second latency is acceptable.

So the first step is to set a latency threshold in milliseconds. The Redis latency-monitor-threshold directive sets a limit in milliseconds that will log all or some of the commands and activity of the Redis instance that exceed that limit with a default of 0. This means Redis does not automatically run latency monitoring but must be actively set.

Only events that will take more than a specific threshold will log as latency spikes. The user should set the threshold according to their needs.

For example, if the maximum acceptable latency is 100 milliseconds, the threshold is to set to such a value in order to log all the events blocking the server for a time equal or greater to 100 milliseconds.

We can enable the latency monitor with the following command:

CONFIG SET latency-monitor-threshold 100

By default, the threshold is 0. However, while the memory requirements of latency monitoring are very small, there is no good reason to raise the baseline memory usage of a Redis instance that is working well.

[Can’t enable latency monitoring? We’d be happy to assist!]

 

Information reporting with the LATENCY command

The user interface to the latency monitoring subsystem is the LATENCY command. Like many other Redis commands, LATENCY accepts subcommands that modify its behavior.

These subcommands are:

  • LATENCY LATEST – returns the latest latency samples for all events.
  • LATENCY HISTORY – returns latency time series for a given event.
  • LATENCY RESET – resets latency time-series data for one or more events.
  • LATENCY GRAPH – renders an ASCII-art graph of an event’s latency samples.
  • LATENCY DOCTOR – replies with a human-readable latency analysis report.

The LATENCY DOCTOR command reports about different latency-related issues and advises about possible remedies.

This command is the most powerful analysis tool in the latency monitoring framework. It is able to provide additional statistical data. For instance, the average period between latency spikes, the median deviation, and a human-readable analysis of the event.

[Stuck in between the analysis? We are here for you!]

 

Conclusion

In short, Redis Latency Monitoring helps the user to check and troubleshoot possible latency problems. Today, we saw various aspects of Latency Monitoring and how it helps Redis.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF