How to enable Profiling in HAProxy

With the release of HAProxy 1.9, you can record CPU time spent on processing a request within HAProxy. Add the profiling.tasks directive to your global section:


global
    profiling.tasks on

There are new fetch methods that expose the profiling metrics:

Fetch methodDescription
date_usThe microseconds part of the date.
cpu_callsThe number of calls to the task processing the stream or current request since it was allocated. It is reset for each new request on the same connection.
cpu_ns_avgThe average number of nanoseconds spent in each call to the task processing the stream or current request.
cpu_ns_totThe total number of nanoseconds spent in each call to the task processing the stream or current request.
lat_ns_avgThe average number of nanoseconds spent between the moment the task handling the stream is woken up and the moment it is effectively called.
lat_ns_totThe total number of nanoseconds between the moment the task handling the stream is woken up and the moment it is effectively called.

Add these to your log messages like this:

log-format "%{+Q}r cpu_calls:%[cpu_calls] cpu_ns_tot:%[cpu_ns_tot] cpu_ns_avg:%[cpu_ns_avg] lat_ns_tot:%[lat_ns_tot] lat_ns_avg:%[lat_ns_avg]"
# Outputs: "GET / HTTP/1.1" cpu_calls:2 cpu_ns_tot:7928946 cpu_ns_avg:3964473 lat_ns_tot:49814 lat_ns_avg:24907

This is a great way to gauge which requests cost the most to process.


Comments

Leave a Reply

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


Keep up, get in touch.

Follow

Instagram / Facebook

Designed with WordPress