]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: acl: add fetch for server session rate
authorTait Clarridge <tait@taiter.com>
Thu, 6 Dec 2012 02:39:31 +0000 (21:39 -0500)
committerWilly Tarreau <w@1wt.eu>
Thu, 6 Dec 2012 06:52:09 +0000 (07:52 +0100)
Considering there is no option yet for maxconnrate for servers, I wrote
an ACL to check a backend server session rate which we use to send to an
"overflow" backend to prevent latency responses to our clients (very
sensitive latency requirements).

doc/configuration.txt
src/backend.c

index 81cd231bc97786659c70d1c9fb6bdc11741a59c1..7e9f069e890cd293b9320270a8673670bf91d114 100644 (file)
@@ -8021,6 +8021,20 @@ be_sess_rate(<backend>) <integer>
             acl being_scanned be_sess_rate gt 100
             redirect location /denied.html if being_scanned
 
+srv_sess_rate(<backend>/<server>) <integer>
+  Returns true when the sessions creation rate on the server matches the
+  specified values or ranges, in number of new sessions per second. This is
+  used to switch to an alternate backend when an expensive or fragile one
+  reaches too high a session rate, or to limit abuse of service (eg. prevent
+  latent requests from overloading servers).
+
+  Example :
+        # Redirect to a separate back
+        acl srv1_full srv_sess_rate(be1/srv1) gt 50
+        acl srv2_full srv_sess_rate(be1/srv2) gt 50
+        use_backend be2 if srv1_full or srv2_full
+
+
 connslots <integer>
 connslots(<backend>) <integer>
   The basic idea here is to be able to measure the number of connection "slots"
index f4b90ced35a55d94f48d6518bdf01a4aa8e4fa8d..96545a9918d3bd4fa861d28035b0a995e98abbf7 100644 (file)
@@ -1587,6 +1587,20 @@ acl_fetch_srv_conn(struct proxy *px, struct session *l4, void *l7, unsigned int
        return 1;
 }
 
+/* set temp integer to the number of enabled servers on the proxy.
+ * Accepts exactly 1 argument. Argument is a server, other types will lead to
+ * undefined behaviour.
+ */
+static int
+acl_fetch_srv_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+                        const struct arg *args, struct sample *smp)
+{
+       smp->flags = SMP_F_VOL_TEST;
+       smp->type = SMP_T_UINT;
+       smp->data.uint = read_freq_ctr(&args->data.srv->sess_per_sec);
+       return 1;
+}
+
 /* Note: must not be declared <const> as its list will be overwritten.
  * Please take care of keeping this list alphabetically sorted.
  */
@@ -1601,6 +1615,7 @@ static struct acl_kw_list acl_kws = {{ },{
        { "srv_conn",     acl_parse_int,     acl_fetch_srv_conn,       acl_match_int,     ACL_USE_NOTHING, ARG1(1,SRV) },
        { "srv_id",       acl_parse_int,     acl_fetch_srv_id,         acl_match_int,     ACL_USE_RTR_INTERNAL, 0 },
        { "srv_is_up",    acl_parse_nothing, acl_fetch_srv_is_up,      acl_match_nothing, ACL_USE_NOTHING, ARG1(1,SRV) },
+       { "srv_sess_rate", acl_parse_int,    acl_fetch_srv_sess_rate,  acl_match_int,     ACL_USE_NOTHING, ARG1(1,SRV) },
        { NULL, NULL, NULL, NULL },
 }};