Dragonfly Cloud announces new enterprise security features - learn more

Dragonfly

Question: What is the difference between p95 and p99 latency in performance metrics?

Answer

Latency" in computing refers to the delay before a transfer of data begins following an instruction for its transfer. It's a crucial aspect of understanding system performance and user experience, especially in distributed systems.

When we talk about "p95" and "p99" latencies, we are referring to percentile latencies. These numbers represent the maximum response time experienced by 95% and 99% of requests respectively.

It's worth mentioning that p99 latency represents more extreme outliers in your system's performance than p95 latency. Thus, if you're optimizing for the best performance under peak conditions, paying attention to p99 latency can be more important because it helps ensure good experiences even for those users who might otherwise have unusually long wait times.

For example, consider a simple method for measuring request latency in Python using the time module:

import time

def measure_latency(func):
    start_time = time.time()
    func()
    end_time = time.time()
    latency = end_time - start_time
    return latency

You could collect these latencies over time for all requests, then calculate the p95 and p99 latencies like so:

import numpy as np

# Assume `latencies` is a list of latency measurements
p95_latency = np.percentile(latencies, 95)
p99_latency = np.percentile(latencies, 99)

In this code, np.percentile() calculates the desired percentile value (in our case, p95 or p99) from the given list of latencies.

While both p95 and p99 are useful metrics, they serve different purposes based on your performance optimization goals. In general, monitoring various percentiles can give you a more holistic view of your system's performance.

Was this content helpful?

Other Common Database Performance Questions (and Answers)

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost