]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: faster lookup for duplicated proxy name
authorWilly Tarreau <w@1wt.eu>
Sat, 15 Mar 2014 07:17:08 +0000 (08:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 15 Mar 2014 07:21:42 +0000 (08:21 +0100)
cfg_parse_listen() currently checks for duplicated proxy names.
Now that we have a tree for this, we can use it.

The config load time was further reduced by 1.6, which is now
about 4.5 times faster than what it was without the trees.

In fact it was the last CPU-intensive processing involving proxy
names. Now the only remaining point is the automatic fullconn
computation which can be bypassed by having a fullconn in the
defaults section, reducing the load time by another 10x.

src/cfgparse.c

index ceaa96e4a9c77772abdd45dfe251fa9f54b25029..5589ec03f71f8559e73b8f3e02c9fea975ffca84 100644 (file)
@@ -1775,6 +1775,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                rc = PR_CAP_NONE;
 
        if (rc != PR_CAP_NONE) {  /* new proxy */
+               struct ebpt_node *node;
+
                if (!*args[1]) {
                        Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
                              "  optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
@@ -1790,7 +1792,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_ALERT | ERR_FATAL;
                }
 
-               for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
+               for (node = ebis_lookup(&proxy_by_name, args[1]); node; node = ebpt_next(node)) {
+                       curproxy = container_of(node, struct proxy, conf.by_name);
+
+                       if (strcmp(curproxy->id, args[1]) != 0)
+                               break;
+
                        /*
                         * If there are two proxies with the same name only following
                         * combinations are allowed:
@@ -1802,9 +1809,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                         *      ruleset            -      -       -        -
                         */
 
-                       if (!strcmp(curproxy->id, args[1]) &&
-                               (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) &&
-                               (rc!=(PR_CAP_BE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_FE|PR_CAP_RS))) {
+                       if ((rc != (PR_CAP_FE|PR_CAP_RS) || curproxy->cap != (PR_CAP_BE|PR_CAP_RS)) &&
+                           (rc != (PR_CAP_BE|PR_CAP_RS) || curproxy->cap != (PR_CAP_FE|PR_CAP_RS))) {
                                Warning("Parsing [%s:%d]: %s '%s' has same name as another %s (declared at %s:%d).\n",
                                        file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
                                        curproxy->conf.file, curproxy->conf.line);