]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: clock: measure the total boot time
authorWilly Tarreau <w@1wt.eu>
Wed, 17 May 2023 07:02:21 +0000 (09:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 May 2023 07:33:54 +0000 (09:33 +0200)
Some huge configs take a significant amount of time to start and this
can cause some trouble (e.g. health checks getting delayed and grouped,
process not responding to the CLI etc). For example, some configs might
start fast in certain environments and slowly in other ones just due to
the use of a wrong DNS server that delays all libc's resolutions. Let's
first start by measuring it by keeping a copy of the most recently known
ready date, once before calling check_config_validity() and then refine
it when leaving this function. A last call is finally performed just
before deciding to split between master and worker processes, and it covers
the whole boot. It's trivial to collect and even allows to get rid of a
call to clock_update_date() in function check_config_validity() that was
used in hope to better schedule future events.

include/haproxy/clock.h
src/cfgparse.c
src/clock.c
src/haproxy.c

index 11eae4f6a2f6241800cf2c986cf8d7ec3b42b53f..8ce41e79e68e1eb53c0abc06c9fd2f08d1c2fcb4 100644 (file)
@@ -26,6 +26,7 @@
 #include <haproxy/api.h>
 
 extern struct timeval              start_date;    /* the process's start date in wall-clock time */
+extern struct timeval              ready_date;    /* date when the process was considered ready */
 extern ullong                      start_time_ns; /* the process's start date in internal monotonic time (ns) */
 extern volatile ullong             global_now_ns; /* common monotonic date between all threads, in ns (wraps every 585 yr) */
 
index 328836af5d72b66feab6766465daaf0031ba3815..84c8cfa0cc5aebdc23ace930709603fcf46b8513 100644 (file)
@@ -2771,9 +2771,6 @@ int check_config_validity()
         * Now, check for the integrity of all that we have collected.
         */
 
-       /* will be needed further to delay some tasks */
-       clock_update_date(0,1);
-
        if (!global.tune.max_http_hdr)
                global.tune.max_http_hdr = MAX_HTTP_HDR;
 
index 1b180e35b13bcfc011fd64c2f6d9bfdf34208c43..7cf71607fe47055be6741706649e5a087f05aba0 100644 (file)
@@ -27,6 +27,7 @@
 #include <haproxy/tools.h>
 
 struct timeval                   start_date;      /* the process's start date in wall-clock time */
+struct timeval                   ready_date;      /* date when the process was considered ready */
 ullong                           start_time_ns;   /* the process's start date in internal monotonic time (ns) */
 volatile ullong                  global_now_ns;   /* common monotonic date between all threads, in ns (wraps every 585 yr) */
 volatile uint                    global_now_ms;   /* common monotonic date in milliseconds (may wrap) */
index 2bd42a95f7b3f1bbe7c47457cb3343d009fdf8bc..35aac95a00dc845984fcaabf8615524acdd9af58 100644 (file)
@@ -2247,8 +2247,19 @@ static void init(int argc, char **argv)
                exit(1);
        }
 
+       /* update the ready date that will be used to count the startup time
+        * during config checks (e.g. to schedule certain tasks if needed)
+        */
+       clock_update_date(0, 1);
+       ready_date = date;
+
        /* Note: global.nbthread will be initialized as part of this call */
        err_code |= check_config_validity();
+
+       /* update the ready date to also account for the check time */
+       clock_update_date(0, 1);
+       ready_date = date;
+
        for (px = proxies_list; px; px = px->next) {
                struct server *srv;
                struct post_proxy_check_fct *ppcf;
@@ -3508,6 +3519,10 @@ int main(int argc, char **argv)
                                 global.maxsock);
        }
 
+       /* update the ready date a last time to also account for final setup time */
+       clock_update_date(0, 1);
+       ready_date = date;
+
        if (global.mode & (MODE_DAEMON | MODE_MWORKER | MODE_MWORKER_WAIT)) {
                int ret = 0;
                int in_parent = 0;