percentile apache server request response times

I needed a hack to quickly find the 95th percentile of apache request response times. For example I needed to be able to say that “95% of our apache requests are served in X milliseconds or less.” In the apache2 config the LogFormat directive had %D (the time taken to serve the request, in microseconds) as the last field. Meaning the last field of each log line would be the time it took to serve the request. This would make it easy to pull out with $NF in awk

# PCT=.95; NR=`cat access.log | wc -l `; cat /var/log/apache2/access.log | awk '{print $NF}' | sort -rn | tail -n+$(echo "$NR-($NR*$PCT)" |bc | cut -d. -f1) |head -1
938247

In this case 95% of the apache requests were served in 938 milliseconds or less (WTF?!). Then run on an aggregated group of logs, or change the date/time range to just run for logs on a particular day, or for multiple time periods.

Note: I couldn’t get scale to work here in bc for some reason.

2 thoughts on “percentile apache server request response times

  1. using awk instead of tail/head

    PCT=.95; NR=`cat access.log | wc -l `; cat access.log | awk '{print $NF}' | sort -rn | awk -va=$(echo "$NR-($NR*$PCT)" |bc | cut -d. -f1) 'NR==a {print}'
  2. using cat/grep instead of tail/head

    PCT=.95; NR=`cat access.log | wc -l `; cat access.log | awk '{print $NF}' | sort -rn | cat -n | grep -m1 "\<$(echo "$NR-($NR*$PCT)" |bc | cut -d. -f1)\>" | awk '{print $2}'

Leave a Reply

Your email address will not be published. Required fields are marked *