[Popcon-developers] Bug#459910: please randomize the submission time (to prevent to DDoS popcon.debian.org)

Petter Reinholdtsen pere at hungry.com
Wed Jan 9 17:38:46 UTC 2008


[Holger Levsen]
> As discussed on irc this is because all clients hammer
> popcon.debian.org on the same day at the same time (in their local
> timezone at least) once a week, so many submissions get lost.

Here is a draft patch to implement a random sleep.  The patch is
mostly cut-n-paste from sitesummary, which did the same for cron-apt,
but is as it stand not tested in popularity-contest.

Index: default.conf
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/default.conf,v
retrieving revision 1.6
diff -u -3 -p -u -r1.6 default.conf
--- default.conf        8 Jan 2008 17:01:44 -0000       1.6
+++ default.conf        9 Jan 2008 17:36:06 -0000
@@ -39,6 +39,10 @@ USEHTTP="yes"
 # HTTP_PROXY="http://proxy:port". This overrides the environment
 # variable http_proxy.

+# Random sleep between 0 and $RUNSLEEP seconds before running.  3600
+# is one hour.
+RUNSLEEP="3600"
+
 # MY_HOSTID is a secret number that the popularity-contest receiver
 # uses to keep track of your submissions.  Whenever you send in a
 # new entry, it overwrites the last one that had the same HOSTID.
Index: debian/cron.weekly
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/debian/cron.weekly,v
retrieving revision 1.22
diff -u -3 -p -u -r1.22 cron.weekly
--- debian/cron.weekly  8 Jan 2008 17:01:44 -0000       1.22
+++ debian/cron.weekly  9 Jan 2008 17:36:06 -0000
@@ -26,6 +26,22 @@ if [ -n "$HTTP_PROXY" ]; then
   export http_proxy="$HTTP_PROXY";
 fi

+# Sleep a random number of seconds to avoid all clients connecting to
+# the server at the same time.  Based on code from the cron-apt and
+# sitesummary package.
+if [ -n "$RUNSLEEP" ] ; then
+    if [ $RUNSLEEP -gt 0 ] ; then
+        if [ -z "$RANDOM" ] ; then
+            # A fix for shells that do not have this bash feature.
+            RANDOM=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c"1-5"
+)
+        fi
+        TIME=$(($RANDOM % $RUNSLEEP))
+        sleep $TIME
+    fi
+fi
+
+
 # keep old logs
 cd /var/log
 umask 022

Happy hacking,
-- 
Petter Reinholdtsen






More information about the Popcon-developers mailing list