"Percentile latencies" are commonly used metrics to understand the distribution of request response times in databases or other systems. Specifically, p50 and p95 are two such percentile metrics.
P50 (or the 50th percentile) latency means that 50% of the requests have a latency time less than this value. In other words, it's the median response time. If your p50 latency is 200 milliseconds, that means half of your requests return in 200 ms or less.
The p95 metric gives a different perspective - it indicates the latency at which 95% of requests are serviced. For example, if your p95 latency is 500 milliseconds, it means 95% of all requests were processed within this duration. This metric helps identify outliers and forms an understanding of the worst-case scenario for most users.
To illustrate this with a code snippet, let's assume we have an array
latencies in Python that contains latency data:
This script calculates and prints the p50 and p95 latency based on the given data. It's important to keep in mind that both p50 and p95 latency are valuable for understanding the performance of your database. While p50 gives a general sense of typical performance, p95 can help you prepare your system for high-load scenarios or diagnose issues affecting a small but significant slice of requests.