[CalendarServer-changes] [3867] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 16 11:42:43 PDT 2009


Revision: 3867
          http://trac.macosforge.org/projects/calendarserver/changeset/3867
Author:   wsanchez at apple.com
Date:     2009-03-16 11:42:42 -0700 (Mon, 16 Mar 2009)
Log Message:
-----------
expovariate the HTTPRetryAfter value

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/twext/web2/channel/http.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2009-03-16 18:14:50 UTC (rev 3866)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2009-03-16 18:42:42 UTC (rev 3867)
@@ -678,6 +678,7 @@
             maxRequests = config.MaxRequests,
             retryAfter = config.HTTPRetryAfter,
             betweenRequestsTimeOut = config.IdleConnectionTimeOut,
+            expovariate = True,
         )
 
         def updateChannel(config, items):

Modified: CalendarServer/trunk/twext/web2/channel/http.py
===================================================================
--- CalendarServer/trunk/twext/web2/channel/http.py	2009-03-16 18:14:50 UTC (rev 3866)
+++ CalendarServer/trunk/twext/web2/channel/http.py	2009-03-16 18:42:42 UTC (rev 3867)
@@ -14,6 +14,8 @@
 # limitations under the License.
 ##
 
+from random import expovariate
+
 from twisted.internet import protocol
 from twisted.python import log
 from twisted.web2.channel.http import HTTPFactory
@@ -53,16 +55,22 @@
     """
     Factory for HTTP server which emits a 503 response when overloaded.
     """
-    def __init__(self, requestFactory, maxRequests=600, retryAfter=0, **kwargs):
+    def __init__(self, requestFactory, maxRequests=600, retryAfter=0, expovariate=False, **kwargs):
         self.retryAfter = retryAfter
+        self.expovariate = expovariate
         HTTPFactory.__init__(self, requestFactory, maxRequests, **kwargs)
 
     def buildProtocol(self, addr):
+        if self.expovariate:
+            retryAfter = int(expovariate(1.0/self.retryAfter))
+        else:
+            retryAfter = self.retryAfter
+
         if self.outstandingRequests >= self.maxRequests:
-            return OverloadedLoggingServerProtocol(self.retryAfter, self.outstandingRequests)
-        
+            return OverloadedLoggingServerProtocol(retryAfter, self.outstandingRequests)
+
         p = protocol.ServerFactory.buildProtocol(self, addr)
-        
+
         for arg,value in self.protocolArgs.iteritems():
             setattr(p, arg, value)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090316/0b3a8293/attachment-0001.html>


More information about the calendarserver-changes mailing list