I'm in the process of setting up one haproxy instance now, and I find
the following acl option useful. I'm not too sure why this option has
not been available before, but I find this useful for my own usage, so
I'm submitting this patch in the hope that it will be useful as well.
The basic idea is to be able to measure the available connection slots still available (connection, + queue) - anything beyond that can be redirected to a different backend. 'nbsrvconnslots' = number of available server connection slots, + number of available server queue slots. In the case where we encounter srv maxconn = 0, or srv maxqueue = 0 (in which case we dont need to care about nbsrvconnslots) the value you get is -999 (let me know if you think another value is better). Note also that this code does not take care of dynamic connections at this point in time.
The reason why I'm using this new acl (as opposed to 'nbsrv') is that 'nbsrv' only measures servers that are actually *down*. Whereas this other acl is more fine-grained, and looks into the number of conn slots available as well.
Comments are welcome.
-jf
diff -ur ha/src/backend.c haproxy-1.3.15.2/src/backend.c
--- ha/src/backend.c 2008-06-22 03:59:05.000000000 +0800
+++ haproxy-1.3.15.2/src/backend.c 2008-08-24 17:21:03.506634328 +0800
@@ -2115,9 +2115,40 @@
}
+/* fetch number of available server connection slots - ***inclusive of queue slots!!! so eg. if a server is maxconn-ed out..., but it has 10 available queue slots, this
+ * function will still return 10 for that server... */ +static int +acl_fetch_nbsrvconnslots(struct proxy *px, struct session *l4, void *l7, int dir, + struct acl_expr *expr, struct acl_test *test) +{ + struct server *iterator; + test->flags = ACL_TEST_F_VOL_TEST; + if (expr->arg_len) { + /* another proxy was designated, we must look for it */ + for (px = proxy; px; px = px->next) + if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str)) + break; + } + if (!px) + return 0; + + test->i = 0; + iterator = px->srv; + while (iterator) { + if ((iterator->state & 1) == 0) { iterator = iterator->next; continue; } + if (iterator->maxconn == 0 || iterator->maxqueue == 0){ test->i = -999; return 1; }
+ iterator = iterator->next; + } + + return 1; +} +
{ "nbsrv", acl_parse_int, acl_fetch_nbsrv, acl_match_int }, + { "nbsrvconnslots", acl_parse_int, acl_fetch_nbsrvconnslots, acl_match_int }, { NULL, NULL, NULL, NULL },
-- In the meantime, here is your PSA: "It's so hard to write a graphics driver that open-sourcing it would not help." -- Andrew Fear, Software Product Manager, NVIDIA Corporation http://kerneltrap.org/node/7228Received on 2008/08/24 11:37
This archive was generated by hypermail 2.2.0 : 2008/08/24 11:45 CEST