dma - Randomize the retry timeouts a bit
authorMatthias Schmidt <matthias@dragonflybsd.org>
Mon, 20 Sep 2010 08:51:24 +0000 (10:51 +0200)
committerMatthias Schmidt <matthias@dragonflybsd.org>
Mon, 20 Sep 2010 08:51:24 +0000 (10:51 +0200)
Author: Peter Pentchev <roam@ringlet.net>

libexec/dma/dma.c
libexec/dma/dma.h

index a669dc2..83f2bbb 100644 (file)
@@ -270,7 +270,7 @@ static void
 deliver(struct qitem *it)
 {
        int error;
-       unsigned int backoff = MIN_RETRY;
+       unsigned int backoff = it->remote? MIN_RETRY: MIN_RETRY_LOCAL;
        const char *errmsg = "unknown bounce reason";
        struct timeval now;
        struct stat st;
@@ -302,7 +302,13 @@ retry:
                        goto bounce;
                }
                sleep(backoff);
-               backoff *= 2;
+               backoff = backoff * 2 + (
+#ifdef HAVE_RANDOM
+                       random()
+#else
+                       rand()
+#endif
+                       % RETRY_JITTER);
                if (backoff > MAX_RETRY)
                        backoff = MAX_RETRY;
                goto retry;
index 5d971c0..5052050 100644 (file)
@@ -48,7 +48,9 @@
 
 #define BUF_SIZE       2048
 #define MIN_RETRY      300             /* 5 minutes */
+#define MIN_RETRY_LOCAL        30              /* 30 seconds */
 #define MAX_RETRY      (3*60*60)       /* retry at least every 3 hours */
+#define RETRY_JITTER   10
 #define MAX_TIMEOUT    (5*24*60*60)    /* give up after 5 days */
 #ifndef PATH_MAX
 #define PATH_MAX       1024            /* Max path len */