Dragonfly Cloud is now available on the AWS Marketplace - Learn More

Question: How can you calculate the P90 latency?

Answer

P90 latency refers to the 90th percentile of response times in a distribution. It is a common metric used to evaluate the performance of databases, services, and applications.

To calculate P90 latency from a list of latencies in milliseconds, follow these steps:

  1. Sort the latencies in ascending order.
  2. Determine the index for the 90th percentile using the formula: index = round((90/100) * len(latencies))
  3. Retrieve the latency at that index.

Here's a simple Python code example that demonstrates this:

def calculate_p90(latencies): sorted_latencies = sorted(latencies) index = round((90/100) * len(sorted_latencies)) return sorted_latencies[index-1] # Subtract 1 since indexing starts at 0 latencies = [15, 20, 35, 40, 50, 60, 70, 80, 100] print(calculate_p90(latencies)) # Output: 80

This method calculates the exact value at position P90. However, sometimes interpolation between adjacent values might be required if the computed index isn't an integer or if more precision is needed.

Please note that latency metrics like P90 are useful because they provide insights into the long tail of your latency distribution which average latency wouldn't reveal. A high P90 (or other high percentiles like P95 or P99) indicates that a significant portion of your users are experiencing high latencies, which could suggest performance issues.

Was this content helpful?

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