>_ IzzyLab

Hands-on task

This task is step 11 of the course “Logs: analysis and housekeeping”

Checkout latency p95

medium~7 min

/var/log/checkout/latency_ms.txt has 130 checkout times in ms, one per line, in random order. Compute the 95th percentile using the nearest-rank method: sort in ascending order and take the element number ceil(0.95 × N) (numbering from 1). Write the number to /root/checkout_p95.txt.

What you'll practise:
  • p95 percentile
  • nearest-rank
  • ceil
  • sort -n
  • awk

Topic breakdown

p95 is the value that 95% of requests don't exceed; latency SLOs are built on it because the mean hides the slow tail. The nearest-rank method: sort the series and take element number ceil(p/100 × N). When N is not a multiple of 20, the product is fractional, and it's easy to be off by one element: truncation with int() rounds down, while the method needs rounding up. Shell integer arithmetic knows nothing about fractions, so such calculations are done in awk.

What's checked

  1. p95 computed correctly

What it looks like