]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: task: maintain a per-thread indicator of the peak run-queue size
authorWilly Tarreau <w@1wt.eu>
Thu, 19 Mar 2026 14:18:32 +0000 (15:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Mar 2026 15:24:31 +0000 (16:24 +0100)
The new field th_ctx->rq_tot_peak contains the computed peak run queue
length averaged over the last 512 calls. This is computed when entering
process_runnable_tasks. It will not take into account new tasks that are
created or woken up during this round nor those which are evicted, which
is the reason why we're using a peak measurement to increase chances to
observe transient high values. Tests have shown that 512 samples are good
to provide a relatively smooth average measurement while still fading
away in a matter of milliseconds at high loads. Since this value is
only updated once per round, it cannot be used as a statistic and
shouldn't be exposed, it's only for internal use (self-regulation).

include/haproxy/defaults.h
include/haproxy/tinfo-t.h
src/task.c

index 72a9bc13a07cd608b513ac2048ad47e59529387e..2c9896047737fd7bb3e8350632fbe568197a651e 100644 (file)
 #define TIME_STATS_SAMPLES 512
 #endif
 
+/* number of samples used to measure the load in the run queue */
+#ifndef RQ_LOAD_SAMPLES
+#define RQ_LOAD_SAMPLES 512
+#endif
+
 /* max ocsp cert id asn1 encoded length */
 #ifndef OCSP_MAX_CERTID_ASN1_LENGTH
 #define OCSP_MAX_CERTID_ASN1_LENGTH 128
index 031b491d8d804e5667aafb20fd9783b68dbe651f..af74e4ff7102648c93c4da9556a268568944d0ce 100644 (file)
@@ -233,6 +233,7 @@ struct thread_ctx {
        struct buffer *last_dump_buffer;        /* Copy of last buffer used for a dump; may be NULL or invalid; for post-mortem only */
        unsigned long long total_streams;       /* Total number of streams created on this thread */
        unsigned int stream_cnt;                /* Number of streams attached to this thread */
+       unsigned int rq_tot_peak;               /* total run queue size last call */
 
        // around 68 bytes here for shared variables
 
index 8f03b1ddadebe72ac98349e2295e0e4bfe91897a..939a5d8b006d7c7a41cbbe6911b174fd8bf2c6a5 100644 (file)
@@ -738,6 +738,8 @@ void process_runnable_tasks()
 
        _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_STUCK); // this thread is still running
 
+       swrate_add_peak_local(&th_ctx->rq_tot_peak, RQ_LOAD_SAMPLES, th_ctx->rq_total);
+
        if (!thread_has_tasks()) {
                activity[tid].empty_rq++;
                return;