Question: What is the difference between P50 and P90 latency in database performance?

Answer

P50 and P90 are statistical terms used to understand the performance of a system, such as a database, under load. They are percentiles that help interpret the distribution of response times.

P50 Latency (also known as Median Latency): This value represents the point below which 50% of the observations fall. In other words, 50% of your queries will get a response in less time than the P50 latency.

P90 Latency: P90 latency is the point where 90% of the measurements fall below that value. It means 90% of your queries will get a response in less than the P90 latency.

The main reason to measure P50, P90, or even P99 latencies instead of average latency is because they give a much better understanding of outliers. Average latency can be heavily influenced by a few extremely slow requests, whereas percentiles like P90 give a more realistic picture of what most users are experiencing.

Here's a simple Python example showing how you might calculate P50 and P90 latencies from a list of latency data:

import numpy as np # Assume this list contains latency data in milliseconds latencies = [13, 18, 14, 35, 24, 18, 23, 45, 32, 28, 19, 26, 21, 29, 34] p50_latency = np.percentile(latencies, 50) p90_latency = np.percentile(latencies, 90) print(f'P50 Latency: {p50_latency} ms') print(f'P90 Latency: {p90_latency} ms')

In this example, if the output is P50 Latency: 24 ms and P90 Latency: 35 ms, it means that 50% of your requests are served within 24 ms, and 90% of your requests are served within 35 ms.

Analyzing P50 and P90 latencies can help you identify if a significant proportion of your queries are slower than an acceptable threshold. It allows you to optimize your database for better overall performance.

Was this content helpful?

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.