[CalendarServer-changes] [4562] CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/ twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 29 16:35:01 PDT 2009


Revision: 4562
          http://trac.macosforge.org/projects/calendarserver/changeset/4562
Author:   sagen at apple.com
Date:     2009-09-29 16:34:57 -0700 (Tue, 29 Sep 2009)
Log Message:
-----------
Adds a new LimitingHTTPFactory whose protocol, LimitingHTTPChannel, removes its port file descriptor from the reactor when the maximum number of outstanding requests is reached, adding it back to the reactor when the outstanding request count falls back under that threshold.

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/httpfactory.py
    CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/tap.py

Modified: CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/httpfactory.py
===================================================================
--- CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/httpfactory.py	2009-09-29 18:03:38 UTC (rev 4561)
+++ CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/httpfactory.py	2009-09-29 23:34:57 UTC (rev 4562)
@@ -18,7 +18,7 @@
 
 from twisted.internet import protocol
 from twisted.python import log
-from twisted.web2.channel.http import HTTPFactory
+from twisted.web2.channel.http import HTTPFactory, HTTPChannel
 
 from twistedcaldav.config import config
 
@@ -61,3 +61,21 @@
         for arg,value in self.protocolArgs.iteritems():
             setattr(p, arg, value)
         return p
+
+
+class LimitingHTTPChannel(HTTPChannel):
+
+    def connectionMade(self):
+        HTTPChannel.connectionMade(self)
+        if self.factory.outstandingRequests >= self.factory.maxRequests:
+            log.msg("Overload")
+            self.factory.myServer.myPort.stopReading()
+
+    def connectionLost(self, reason):
+        HTTPChannel.connectionLost(self, reason)
+        if self.factory.outstandingRequests < self.factory.maxRequests:
+            self.factory.myServer.myPort.startReading()
+
+class LimitingHTTPFactory(HTTPFactory):
+    protocol = LimitingHTTPChannel
+

Modified: CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/tap.py	2009-09-29 18:03:38 UTC (rev 4561)
+++ CalendarServer/branches/users/sagen/deployment-inherit-fds-4549/twistedcaldav/tap.py	2009-09-29 23:34:57 UTC (rev 4562)
@@ -51,7 +51,7 @@
 from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
 from twistedcaldav.directory.aggregate import AggregateDirectoryService
 from twistedcaldav.directory.sudo import SudoDirectoryService
-from twistedcaldav.httpfactory import HTTP503LoggingFactory
+from twistedcaldav.httpfactory import HTTP503LoggingFactory, LimitingHTTPFactory
 from twistedcaldav.static import CalendarHomeProvisioningFile
 from twistedcaldav.static import TimezoneServiceFile
 from twistedcaldav.timezones import TimezoneCache
@@ -456,18 +456,28 @@
 
 class InheritTCPServer(internet.TCPServer):
 
+    def __init__(self, *args, **kwargs):
+        internet.TCPServer.__init__(self, *args, **kwargs)
+        self.args[1].myServer = self
+
     def _getPort(self):
         from twisted.internet import reactor
         port = InheritedPort(self.args[0], self.args[1], reactor)
         port.startListening()
+        self.myPort = port
         return port
 
 class InheritSSLServer(internet.SSLServer):
 
+    def __init__(self, *args, **kwargs):
+        internet.SSLServer.__init__(self, *args, **kwargs)
+        self.args[1].myServer = self
+
     def _getPort(self):
         from twisted.internet import reactor
         port = InheritedSSLPort(self.args[0], self.args[1], self.args[2], reactor)
         port.startListening()
+        self.myPort = port
         return port
 
 class CalDAVServiceMaker(object):
@@ -700,23 +710,18 @@
 
         site = Site(realRoot)
 
-        channel = HTTP503LoggingFactory(
-            site,
-            maxRequests=config.MaxRequests,
-            betweenRequestsTimeOut=config.IdleConnectionTimeOut)
 
-        def updateChannel(config, items):
-            channel.maxRequests = config.MaxRequests
-
-        config.addHook(updateChannel)
-
-
         # If inheriting file descriptors from the master, use those to handle
         # requests instead of opening ports.
 
         if (config.EnableConnectionInheriting and
            (config.InheritFDs or config.InheritSSLFDs)):
 
+            channel = LimitingHTTPFactory(
+                site,
+                maxRequests=config.MaxRequests,
+                betweenRequestsTimeOut=config.IdleConnectionTimeOut)
+
             for fd in config.InheritFDs:
                 fd = int(fd)
                 inheritedService = InheritTCPServer(
@@ -748,6 +753,11 @@
 
         else: # Not inheriting, therefore open our own:
 
+            channel = HTTP503LoggingFactory(
+                site,
+                maxRequests=config.MaxRequests,
+                betweenRequestsTimeOut=config.IdleConnectionTimeOut)
+
             if not config.BindAddresses:
                 config.BindAddresses = [""]
 
@@ -799,7 +809,12 @@
                         )
                         httpsService.setServiceParent(service)
 
+        def updateChannel(config, items):
+            channel.maxRequests = config.MaxRequests
 
+        config.addHook(updateChannel)
+
+
         # Change log level back to what it was before
         setLogLevelForNamespace(None, oldLogLevel)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090929/ffae03f6/attachment.html>


More information about the calendarserver-changes mailing list