httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pt...@pobox.com
Subject [PATCH] flood: Add URL DELAYFACTOR to customize delays
Date Fri, 07 Feb 2003 15:55:06 GMT
Hi all,

I created the following patch so I could specify delays smaller than
one second.

This patch adds a new attribute called "delayfactor" to the
URL element.  You use it to change the multiplication factor
applied to the values you specify for:
     postdelay
     postdelayprecision
     predelay
     predelayprecision
Flood previously treated all delays in seconds.  With this patch,
you can change the delays to be handled in microseconds, milliseconds,
etc.  The new attribute affects only the current URL element in
which it's used.  If you do not specify delayfactor, then we retain
the existing behavior of treating delays in seconds.

The precision available to you when you specify DELAYFACTOR=1
is in microseconds, which is the documented precision of apr_sleep().

This patch includes an example in file examples/round-robin-example.xml.

Index: config.h.in
===================================================================
RCS file: /home/cvspublic/httpd-test/flood/config.h.in,v
retrieving revision 1.26
diff -u -r1.26 config.h.in
--- config.h.in	29 Jan 2003 06:07:49 -0000	1.26
+++ config.h.in	7 Feb 2003 01:07:42 -0000
@@ -25,6 +25,7 @@
 #define XML_URLLIST_RESPONSE_TEMPLATE "responsetemplate"
 #define XML_URLLIST_RESPONSE_NAME "responsename"
 #define XML_URLLIST_PROXY "proxy"
+#define XML_URLLIST_DELAYFACTOR "delayfactor"
 #define XML_URLLIST_PREDELAY "predelay"
 #define XML_URLLIST_PREDELAYPRECISION "predelayprecision"
 #define XML_URLLIST_POSTDELAY "postdelay"

Index: flood_round_robin.c
===================================================================
RCS file: /home/cvspublic/httpd-test/flood/flood_round_robin.c,v
retrieving revision 1.34
diff -u -r1.34 flood_round_robin.c
--- flood_round_robin.c	3 Feb 2003 17:10:56 -0000	1.34
+++ flood_round_robin.c	7 Feb 2003 01:07:42 -0000
@@ -404,10 +404,33 @@
     /* Parse any attributes. */
     if (e->attr)
     {
+        /* Default the delay factor so that all delays are measured
+           in seconds.  When we're done examining all attributes, we
+           multiply all parsed delay values with the delay factor.
+           Variable delayfactor will be our initialized value below or
+           the value specified as an attribute. */
+        apr_int64_t delayfactor = APR_USEC_PER_SEC;
+
         apr_xml_attr *attr = e->attr;
         while (attr)
         {
-            if (strncasecmp(attr->name, XML_URLLIST_METHOD, 
+            if (strncasecmp(attr->name, XML_URLLIST_DELAYFACTOR, 
+                            FLOOD_STRLEN_MAX) == 0) {
+                char *endptr;
+                delayfactor = strtoll(attr->value, &endptr, 10);
+                /* Allow a delayfactor of zero in case the user wants
+                   to quickly disable all delay specifications for
+                   the URL. */
+                if ((*endptr != '\0') || (delayfactor < 0))
+                {
+                    apr_file_printf(local_stderr, 
+                                    "Attribute %s has invalid value %s.\n",
+                                    XML_URLLIST_DELAYFACTOR, attr->value);
+                    return APR_EGENERAL;
+                }
+                
+            }
+            else if (strncasecmp(attr->name, XML_URLLIST_METHOD, 
                             FLOOD_STRLEN_MAX) == 0) {
                 if (strncasecmp(attr->value, XML_URLLIST_METHOD_POST, 4) == 0)
                     url->method = POST;
@@ -439,7 +462,6 @@
                                     XML_URLLIST_PREDELAY, attr->value);
                     return APR_EGENERAL;
                 }
-                url->predelay *= APR_USEC_PER_SEC;
             }
             else if (strncasecmp(attr->name, XML_URLLIST_PREDELAYPRECISION,
                                  FLOOD_STRLEN_MAX) == 0) {
@@ -452,7 +474,6 @@
                                     XML_URLLIST_PREDELAYPRECISION, attr->value);
                     return APR_EGENERAL;
                 }
-                url->predelayprecision *= APR_USEC_PER_SEC;
             }
             else if (strncasecmp(attr->name, XML_URLLIST_POSTDELAY,
                                  FLOOD_STRLEN_MAX) == 0) {
@@ -465,7 +486,6 @@
                                     XML_URLLIST_POSTDELAY, attr->value);
                     return APR_EGENERAL;
                 }
-                url->postdelay *= APR_USEC_PER_SEC;
             }
             else if (strncasecmp(attr->name, XML_URLLIST_POSTDELAYPRECISION,
                                  FLOOD_STRLEN_MAX) == 0) {
@@ -478,7 +498,6 @@
                                     XML_URLLIST_POSTDELAYPRECISION, attr->value);
                     return APR_EGENERAL;
                 }
-                url->postdelayprecision *= APR_USEC_PER_SEC;
             }
             else if (strncasecmp(attr->name, 
                                  XML_URLLIST_PAYLOAD_TEMPLATE, 
@@ -513,6 +532,20 @@
             }
             attr = attr->next;
         }
+
+        /* We do not really need to check the delay values before
+           multiplying them.  All delay values default to zero.  So
+           the result will still be zero if no delays were specified.
+           We do perform the checks to avoid all the work needed to
+           prepare multiplication operations. */
+        if (url->predelay > 0)
+            url->predelay *= delayfactor;
+        if (url->predelayprecision > 0)
+            url->predelayprecision *= delayfactor;
+        if (url->postdelay > 0)
+            url->postdelay *= delayfactor;
+        if (url->postdelayprecision > 0)
+            url->postdelayprecision *= delayfactor;
     }
     else
     {

Index: examples/round-robin-example.xml
===================================================================
RCS file: /home/cvspublic/httpd-test/flood/examples/round-robin-example.xml,v
retrieving revision 1.7
diff -u -r1.7 round-robin-example.xml
--- examples/round-robin-example.xml	3 Aug 2001 00:08:25 -0000	1.7
+++ examples/round-robin-example.xml	7 Feb 2003 01:07:42 -0000
@@ -7,6 +7,14 @@
     <url method="POST" payload="version=2&amp;keyword=foo&amp;results=20&amp;what=apr.apache.org"
predelay="1" predelayprecision="5">http://search.apache.org/index.cgi</url>
     <url method="HEAD" postdelay="2" postdelayprecision="2">http://www.apache.org/</url>
     <url method="GET" predelay="1" postdelay="1">http://dev.apache.org/</url>
+    <!-- You can use "delayfactor" to change the effective number
+         of microseconds specified by the delay attributes (e.g.,
+         predelay, postdelayprecision).  The default is
+         1,000,000, which make a predelay of 1 wait for 1 second.
+         In the following example, we have a delay factor of
+         500,000 microseconds, which is half a second.  So we end
+         up waiting half a second. -->
+    <url method="GET" delayfactor="500000" predelay="1" postdelay="1">http://httpd.apache.org/</url>
     <url method="POST" payload="version=2&amp;keyword=foo&amp;results=20&amp;what=apr.apache.org">http://search.apache.org/index.cgi</url>
     <url method="POST" payloadparam="random" payloadparamcount="1" payloadtemplate="version=2&amp;keyword=foo$$&amp;results=20&amp;what=apr.apache.org">http://search.apache.org/index.cgi</url>
     <url method="HEAD">http://www.apache.org/</url>

Mime
View raw message