]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: http: add the "set-nice" action to http-request and http-response
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Jun 2013 15:01:13 +0000 (17:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Jun 2013 15:50:26 +0000 (17:50 +0200)
This new action changes the nice factor of the task processing the current
request.

doc/configuration.txt
include/types/proto_http.h
src/proto_http.c

index a0f88273dea2f5ed29669f664ce876c9934a3923..93d2f2cbfd12ef964b6a9ada1cfe2da2a25242bd 100644 (file)
@@ -2668,7 +2668,8 @@ http-check send-state
   See also : "option httpchk", "http-check disable-on-404"
 
 http-request { allow | deny | tarpit | auth [realm <realm>] | redirect <rule> |
-              add-header <name> <fmt> | set-header <name> <fmt> }
+              add-header <name> <fmt> | set-header <name> <fmt> |
+              set-nice <nice> }
              [ { if | unless } <condition> ]
   Access control for Layer 7 requests
 
@@ -2726,6 +2727,15 @@ http-request { allow | deny | tarpit | auth [realm <realm>] | redirect <rule> |
       information to the server, where the header must not be manipulated by
       external users.
 
+    - "set-nice" sets the "nice" factor of the current request being processed.
+      It only has effect against the other requests being processed at the same
+      time. The default value is 0, unless altered by the "nice" setting on the
+      "bind" line. The accepted range is -1024..1024. The higher the value, the
+      nicest the request will be. Lower values will make the request more
+      important than other ones. This can be useful to improve the speed of
+      some requests, or lower the priority of non-important requests. Using
+      this setting without prior experimentation can cause some major slowdown.
+
   There is no limit to the number of http-request statements per instance.
 
   It is important to know that http-request rules are processed very early in
@@ -2761,7 +2771,7 @@ http-request { allow | deny | tarpit | auth [realm <realm>] | redirect <rule> |
   See also : "stats http-request", section 3.4 about userlists and section 7
              about ACL usage.
 
-http-response { allow | deny | add-header <name> <fmt> |
+http-response { allow | deny | add-header <name> <fmt> | set-nice <nice> |
                 set-header <name> <fmt> } [ { if | unless } <condition> ]
   Access control for Layer 7 responses
 
@@ -2797,6 +2807,15 @@ http-response { allow | deny | add-header <name> <fmt> |
       information to the server, where the header must not be manipulated by
       external users.
 
+    - "set-nice" sets the "nice" factor of the current request being processed.
+      It only has effect against the other requests being processed at the same
+      time. The default value is 0, unless altered by the "nice" setting on the
+      "bind" line. The accepted range is -1024..1024. The higher the value, the
+      nicest the request will be. Lower values will make the request more
+      important than other ones. This can be useful to improve the speed of
+      some requests, or lower the priority of non-important requests. Using
+      this setting without prior experimentation can cause some major slowdown.
+
   There is no limit to the number of http-response statements per instance.
 
   It is important to know that http-reqsponse rules are processed very early in
index 6190e6c58e6cf27d8780bcda41aaa8b4d96e49b7..b50375f79092fbebb5d545e966d0a9c1a8eb48c9 100644 (file)
@@ -246,6 +246,7 @@ enum {
        HTTP_REQ_ACT_ADD_HDR,
        HTTP_REQ_ACT_SET_HDR,
        HTTP_REQ_ACT_REDIR,
+       HTTP_REQ_ACT_SET_NICE,
        HTTP_REQ_ACT_MAX /* must always be last */
 };
 
@@ -256,6 +257,7 @@ enum {
        HTTP_RES_ACT_DENY,
        HTTP_RES_ACT_ADD_HDR,
        HTTP_RES_ACT_SET_HDR,
+       HTTP_RES_ACT_SET_NICE,
        HTTP_RES_ACT_MAX /* must always be last */
 };
 
@@ -368,6 +370,7 @@ struct http_req_rule {
                        struct list fmt;       /* log-format compatible expression */
                } hdr_add;                     /* args used by "add-header" and "set-header" */
                struct redirect_rule *redir;   /* redirect rule or "http-request redirect" */
+               int nice;                      /* nice value for HTTP_REQ_ACT_SET_NICE */
        } arg;                                 /* arguments used by some actions */
 };
 
@@ -381,6 +384,7 @@ struct http_res_rule {
                        int name_len;          /* header name's length */
                        struct list fmt;       /* log-format compatible expression */
                } hdr_add;                     /* args used by "add-header" and "set-header" */
+               int nice;                      /* nice value for HTTP_RES_ACT_SET_NICE */
        } arg;                                 /* arguments used by some actions */
 };
 
index 47f413eed437733f3e319c60c21c58bd5cb77183..ed6c90b0552bbc7e6e65acc28e3cf1cbd6ee9f0d 100644 (file)
@@ -3206,6 +3206,10 @@ http_req_get_intercept_rule(struct proxy *px, struct list *rules, struct session
                case HTTP_REQ_ACT_REDIR:
                        return rule;
 
+               case HTTP_REQ_ACT_SET_NICE:
+                       s->task->nice = rule->arg.nice;
+                       break;
+
                case HTTP_REQ_ACT_SET_HDR:
                        ctx.idx = 0;
                        /* remove all occurrences of the header */
@@ -3271,6 +3275,10 @@ http_res_get_intercept_rule(struct proxy *px, struct list *rules, struct session
                        txn->flags |= TX_SVDENY;
                        return rule;
 
+               case HTTP_RES_ACT_SET_NICE:
+                       s->task->nice = rule->arg.nice;
+                       break;
+
                case HTTP_RES_ACT_SET_HDR:
                        ctx.idx = 0;
                        /* remove all occurrences of the header */
@@ -8386,6 +8394,22 @@ struct http_req_rule *parse_http_req_cond(const char **args, const char *file, i
                        } else
                                break;
                }
+       } else if (!strcmp(args[0], "set-nice")) {
+               rule->action = HTTP_REQ_ACT_SET_NICE;
+               cur_arg = 1;
+
+               if (!*args[cur_arg] ||
+                   (*args[cur_arg + 1] && strcmp(args[cur_arg + 1], "if") != 0 && strcmp(args[cur_arg + 1], "unless") != 0)) {
+                       Alert("parsing [%s:%d]: 'http-request %s' expects exactly 1 argument (integer value).\n",
+                             file, linenum, args[0]);
+                       goto out_err;
+               }
+               rule->arg.nice = atoi(args[cur_arg]);
+               if (rule->arg.nice < -1024)
+                       rule->arg.nice = -1024;
+               else if (rule->arg.nice > 1024)
+                       rule->arg.nice = 1024;
+               cur_arg++;
        } else if (strcmp(args[0], "add-header") == 0 || strcmp(args[0], "set-header") == 0) {
                rule->action = *args[0] == 'a' ? HTTP_REQ_ACT_ADD_HDR : HTTP_REQ_ACT_SET_HDR;
                cur_arg = 1;
@@ -8425,7 +8449,7 @@ struct http_req_rule *parse_http_req_cond(const char **args, const char *file, i
                cur_arg = 2;
                return rule;
        } else {
-               Alert("parsing [%s:%d]: 'http-request' expects 'allow', 'deny', 'auth', 'redirect', 'tarpit', 'add-header', 'set-header', but got '%s'%s.\n",
+               Alert("parsing [%s:%d]: 'http-request' expects 'allow', 'deny', 'auth', 'redirect', 'tarpit', 'add-header', 'set-header', 'set-nice', but got '%s'%s.\n",
                      file, linenum, args[0], *args[0] ? "" : " (missing argument)");
                goto out_err;
        }
@@ -8473,6 +8497,22 @@ struct http_res_rule *parse_http_res_cond(const char **args, const char *file, i
        } else if (!strcmp(args[0], "deny")) {
                rule->action = HTTP_RES_ACT_DENY;
                cur_arg = 1;
+       } else if (!strcmp(args[0], "set-nice")) {
+               rule->action = HTTP_RES_ACT_SET_NICE;
+               cur_arg = 1;
+
+               if (!*args[cur_arg] ||
+                   (*args[cur_arg + 1] && strcmp(args[cur_arg + 1], "if") != 0 && strcmp(args[cur_arg + 1], "unless") != 0)) {
+                       Alert("parsing [%s:%d]: 'http-response %s' expects exactly 1 argument (integer value).\n",
+                             file, linenum, args[0]);
+                       goto out_err;
+               }
+               rule->arg.nice = atoi(args[cur_arg]);
+               if (rule->arg.nice < -1024)
+                       rule->arg.nice = -1024;
+               else if (rule->arg.nice > 1024)
+                       rule->arg.nice = 1024;
+               cur_arg++;
        } else if (strcmp(args[0], "add-header") == 0 || strcmp(args[0], "set-header") == 0) {
                rule->action = *args[0] == 'a' ? HTTP_RES_ACT_ADD_HDR : HTTP_RES_ACT_SET_HDR;
                cur_arg = 1;
@@ -8493,7 +8533,7 @@ struct http_res_rule *parse_http_res_cond(const char **args, const char *file, i
                                       (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR);
                cur_arg += 2;
        } else {
-               Alert("parsing [%s:%d]: 'http-response' expects 'allow', 'deny', 'redirect', 'add-header', 'set-header', but got '%s'%s.\n",
+               Alert("parsing [%s:%d]: 'http-response' expects 'allow', 'deny', 'redirect', 'add-header', 'set-header', 'set-nice', but got '%s'%s.\n",
                      file, linenum, args[0], *args[0] ? "" : " (missing argument)");
                goto out_err;
        }