Skip to content

Command Latency Metrics

Mark Paluch edited this page Jan 25, 2017 · 11 revisions

Command latency metrics give insight about command execution and latencies. Metrics are collected for every completed command and are enabled by default.

Each command is tracked with:

  • Execution count

  • Latency to first response (min, max, percentiles)

  • Latency to complete (min, max, percentiles)

Command latencies are tracked on remote endpoint (distinction by host and port or socket path) and command type level (GET, SET, …​). It is possible to track command latencies on a per-connection level (see DefaultCommandLatencyCollectorOptions).

Command latencies are transported using Events on the EventBus. The EventBus can be obtained from the ClientResources of the client instance. Please keep in mind that the EventBus is used for various event types. Filter on the event type if you’re interested only in particular event types.

RedisClient client = RedisClient.create();
EventBus eventBus = client.getResources().eventBus();

Subscription subscription = eventBus.get()
                .filter(redisEvent -> redisEvent instanceof CommandLatencyEvent)
                .cast(CommandLatencyEvent.class)
                .subscribe(e -> System.out.println(e.getLatencies()));

The EventBus uses rx-java to publish events. This example prints the received latencies to stdout. The interval and the collection of command latency metrics can be configured in the ClientResources.

Prerequisites

Lettuce requires the LatencyUtils dependency (at least 2.0) to provide latency metrics. Make sure to include that dependency on your classpath. Otherwise, you won’t be able using latency metrics.

If using Maven, add the following dependency to your pom.xml:

<dependency>
    <groupId>org.latencyutils</groupId>
    <artifactId>LatencyUtils</artifactId>
    <version>2.0.3</version>
</dependency>

Disabling command latency metrics

To disable metrics collection, use own ClientResources with a disabled DefaultCommandLatencyCollectorOptions:

ClientResources res = new DefaultClientResources
        .Builder()
        .commandLatencyCollectorOptions(DefaultCommandLatencyCollectorOptions.disabled())
        .build();

RedisClient client = RedisClient.create(res);

CommandLatencyCollector Options

The following settings are available to configure from DefaultCommandLatencyCollectorOptions:

Name Method Default

Disable metrics tracking

disable

false

Disables tracking of command latency metrics.

Latency time unit

targetUnit

MICROSECONDS

The target unit for command latency values. All values in the CommandLatencyEvent and a CommandMetrics instance are long values scaled to the targetUnit.

Latency percentiles

targetPercentiles

50.0, 90.0, 95.0, 99.0, 99.9

An double-array of percentiles for latency metrics. The CommandMetrics contains a map that holds the percentile value and the latency value according to the percentile.

Reset latencies after publish

resetLatenciesAfterEvent

true

Allows to control whether the latency metrics are reset to zero one they were published. Setting resetLatenciesAfterEvent allows to accumulate metrics over a long period for long-term analytics.

Local socket distinction

localDistinction

false

Enables per connection metrics tracking instead of per host/port. If true, multiple connections to the same host/connection point will be recorded separately which allows to inspect every connection individually. If false, multiple connections to the same host/connection point will be recorded together. This allows a consolidated view on one particular service.

EventPublisher Options

The following settings are available to configure from DefaultEventPublisherOptions:

Name Method Default

Disable event publisher

disable

false

Disables event publishing.

Event publishing time unit

eventEmitIntervalUnit

MINUTES

The TimeUnit for the event publishing interval.

Event publishing interval

eventEmitInterval

10

The interval for the event publishing.

Clone this wiki locally