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:
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.