]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: measure and report an appctx's call rate in "show sess"
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2019 06:41:29 +0000 (08:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2019 14:04:23 +0000 (16:04 +0200)
Very similarly to previous commit doing the same for streams, we now
measure and report an appctx's call rate. This will help catch applets
which do not consume all their data and/or which do not properly report
that they're waiting for something else. Some of them like peers might
theorically be able to exhibit some occasional peeks when teaching a
full table to a nearby peer (e.g. the new replacement process), but
nothing close to what a bogus service can do so there is no risk of
confusion.

include/proto/applet.h
include/types/applet.h
src/applet.c
src/stream.c

index 91d7be25bfefea8f7f8d68b8b13984094d8e58c8..62612b5546f3201397cb7c72ce9ba3bb2ffe84ee 100644 (file)
@@ -48,6 +48,9 @@ static inline void appctx_init(struct appctx *appctx, unsigned long thread_mask)
        appctx->chunk = NULL;
        appctx->io_release = NULL;
        appctx->thread_mask = thread_mask;
+       appctx->call_rate.curr_sec = 0;
+       appctx->call_rate.curr_ctr = 0;
+       appctx->call_rate.prev_ctr = 0;
        appctx->state = 0;
 }
 
index 21c0e90e78fde1ba2b8ffe20a8d7b9c677a48b3f..4786b31f2bc033d939b243596c48f9131518fd2d 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef _TYPES_APPLET_H
 #define _TYPES_APPLET_H
 
+#include <types/freq_ctr.h>
 #include <types/hlua.h>
 #include <types/obj_type.h>
 #include <types/proxy.h>
@@ -70,6 +71,7 @@ struct appctx {
        struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */
        unsigned long thread_mask;      /* mask of thread IDs authorized to process the applet */
        struct task *t;                  /* task associated to the applet */
+       struct freq_ctr call_rate;       /* appctx call rate */
 
        union {
                struct {
index 9c591c760a185d2718996e182226855a888c9b53..aacc04b67ab015bde4a27ff6be049f55f329c6fe 100644 (file)
@@ -73,6 +73,9 @@ struct task *task_run_applet(struct task *t, void *context, unsigned short state
        si_cant_get(si);
        si_rx_endp_done(si);
 
+       /* measure the call rate */
+       update_freq_ctr(&app->call_rate, 1);
+
        /* Now we'll try to allocate the input buffer. We wake up the applet in
         * all cases. So this is the applet's responsibility to check if this
         * buffer was allocated or not. This leaves a chance for applets to do
index 7f3e99d140b8cfb775deff693359e43e2a7568d8..1af563d6791daf4f928d4c5ac13c0294d6114548 100644 (file)
@@ -3070,14 +3070,14 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
                }
                else if ((tmpctx = objt_appctx(strm->si[0].end)) != NULL) {
                        chunk_appendf(&trash,
-                                     "  app0=%p st0=%d st1=%d st2=%d applet=%s tmask=0x%lx nice=%d calls=%u cpu=%llu lat=%llu\n",
+                                     "  app0=%p st0=%d st1=%d st2=%d applet=%s tmask=0x%lx nice=%d calls=%u rate=%u cpu=%llu lat=%llu\n",
                                      tmpctx,
                                      tmpctx->st0,
                                      tmpctx->st1,
                                      tmpctx->st2,
                                      tmpctx->applet->name,
                                      tmpctx->thread_mask,
-                                     tmpctx->t->nice, tmpctx->t->calls,
+                                     tmpctx->t->nice, tmpctx->t->calls, read_freq_ctr(&tmpctx->call_rate),
                                      (unsigned long long)tmpctx->t->cpu_time, (unsigned long long)tmpctx->t->lat_time);
                }
 
@@ -3107,14 +3107,14 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
                }
                else if ((tmpctx = objt_appctx(strm->si[1].end)) != NULL) {
                        chunk_appendf(&trash,
-                                     "  app1=%p st0=%d st1=%d st2=%d applet=%s tmask=0x%lx, nice=%d, calls=%u, cpu=%llu, lat=%llu\n",
+                                     "  app1=%p st0=%d st1=%d st2=%d applet=%s tmask=0x%lx nice=%d calls=%u rate=%u cpu=%llu lat=%llu\n",
                                      tmpctx,
                                      tmpctx->st0,
                                      tmpctx->st1,
                                      tmpctx->st2,
                                      tmpctx->applet->name,
                                      tmpctx->thread_mask,
-                                     tmpctx->t->nice, tmpctx->t->calls,
+                                     tmpctx->t->nice, tmpctx->t->calls, read_freq_ctr(&tmpctx->call_rate),
                                      (unsigned long long)tmpctx->t->cpu_time, (unsigned long long)tmpctx->t->lat_time);
                }