[CalendarServer-changes] [5504] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 21 18:11:23 PDT 2010


Revision: 5504
          http://trac.macosforge.org/projects/calendarserver/changeset/5504
Author:   glyph at apple.com
Date:     2010-04-21 18:11:22 -0700 (Wed, 21 Apr 2010)
Log Message:
-----------
Fix some issues with MaxRequests enforcement and UseMetaFD.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
    CalendarServer/trunk/twext/internet/sendfdport.py
    CalendarServer/trunk/twext/web2/metafd.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2010-04-21 23:42:42 UTC (rev 5503)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2010-04-22 01:11:22 UTC (rev 5504)
@@ -860,7 +860,7 @@
 
         for p in xrange(0, config.MultiProcess.ProcessCount):
             if config.UseMetaFD:
-                extraArgs = dict(dispatcher=cl.dispatcher)
+                extraArgs = dict(metaSocket=cl.dispatcher.addSocket())
             else:
                 extraArgs = dict(inheritFDs=inheritFDs,
                                  inheritSSLFDs=inheritSSLFDs)
@@ -1010,15 +1010,16 @@
         on in the subprocess, and speaking TLS on the resulting sockets.
     @type inheritSSLFDs: C{list} of C{int}, or C{None}
 
-    @ivar dispatcher: a socket dispatcher to generate an inherited port from,
-        or C{None}.
+    @ivar metaSocket: an AF_UNIX/SOCK_DGRAM socket (initialized from the
+        dispatcher passed to C{__init__}) that is to be inherited by the
+        subprocess and used to accept incoming connections.
 
-    @type dispatcher: L{InheritedSocketDispatcher} or C{NoneType}
+    @type metaSocket: L{socket.socket}
     """
     prefix = "caldav"
 
     def __init__(self, twistd, tapname, configFile, id, interfaces,
-                 inheritFDs=None, inheritSSLFDs=None, dispatcher=None):
+                 inheritFDs=None, inheritSSLFDs=None, metaSocket=None):
 
         self.twistd = twistd
 
@@ -1034,24 +1035,13 @@
                 return x
         self.inheritFDs = emptyIfNone(inheritFDs)
         self.inheritSSLFDs = emptyIfNone(inheritSSLFDs)
-        self.metaSocket = None
-        self.dispatcher = dispatcher
-
+        self.metaSocket = metaSocket
         self.interfaces = interfaces
 
     def getName(self):
         return '%s-%s' % (self.prefix, self.id)
 
 
-    def getMetaDescriptor(self):
-        """
-        Get the meta-socket file descriptor to inherit.
-        """
-        if self.metaSocket is None:
-            self.metaSocket = self.dispatcher.addSocket()
-        return self.metaSocket.fileno()
-
-
     def getFileDescriptors(self):
         """
         @return: a mapping of file descriptor numbers for the new (child)
@@ -1059,8 +1049,8 @@
         """
         fds = {}
         maybeMetaFD = []
-        if self.dispatcher is not None:
-            maybeMetaFD.append(self.getMetaDescriptor())
+        if self.metaSocket is not None:
+            maybeMetaFD.append(self.metaSocket.fileno())
         for fd in self.inheritSSLFDs + self.inheritFDs + maybeMetaFD:
             fds[fd] = fd
         return fds
@@ -1114,11 +1104,9 @@
                 "-o", "InheritSSLFDs=%s" % (",".join(map(str, self.inheritSSLFDs)),)
             ])
 
-        if self.dispatcher is not None:
-            # XXX this FD is never closed in the parent.  should it be?
-            # (should they *all* be?) -glyph
+        if self.metaSocket is not None:
             args.extend([
-                    "-o", "MetaFD=%s" % (self.getMetaDescriptor(),)
+                    "-o", "MetaFD=%s" % (self.metaSocket.fileno(),)
                 ])
 
         return args

Modified: CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/test/test_caldav.py	2010-04-21 23:42:42 UTC (rev 5503)
+++ CalendarServer/trunk/calendarserver/tap/test/test_caldav.py	2010-04-22 01:11:22 UTC (rev 5504)
@@ -1005,7 +1005,7 @@
             configFile = "/does/not/exist",
             id         = 10,
             interfaces = '127.0.0.1',
-            dispatcher = FakeDispatcher()
+            metaSocket = FakeDispatcher().addSocket()
         )
 
         dspm.addProcessObject(slave, {})

Modified: CalendarServer/trunk/twext/internet/sendfdport.py
===================================================================
--- CalendarServer/trunk/twext/internet/sendfdport.py	2010-04-21 23:42:42 UTC (rev 5503)
+++ CalendarServer/trunk/twext/internet/sendfdport.py	2010-04-22 01:11:22 UTC (rev 5504)
@@ -198,6 +198,14 @@
         selectedSocket.status = self.statusWatcher.newConnectionStatus(selectedSocket.status)
 
 
+    def startDispatching(self):
+        """
+        Start listening on all subprocess sockets.
+        """
+        for subSocket in self._subprocessSockets:
+            subSocket.startReading()
+
+
     def addSocket(self):
         """
         Add a C{sendmsg()}-oriented AF_UNIX socket to the pool of sockets being
@@ -209,7 +217,6 @@
         """
         i, o = socketpair(AF_UNIX, SOCK_DGRAM)
         a = _SubprocessSocket(self, o)
-        a.startReading()
         self._subprocessSockets.append(a)
         return i
 

Modified: CalendarServer/trunk/twext/web2/metafd.py
===================================================================
--- CalendarServer/trunk/twext/web2/metafd.py	2010-04-21 23:42:42 UTC (rev 5503)
+++ CalendarServer/trunk/twext/web2/metafd.py	2010-04-22 01:11:22 UTC (rev 5504)
@@ -74,10 +74,11 @@
         """
         Service.startService(self)
         self.reportingFactory = ReportingHTTPFactory(self.site, vary=True)
-        self.reportingFactory.inheritedPort = InheritedPort(
+        inheritedPort = self.reportingFactory.inheritedPort = InheritedPort(
             self.fd, self.createTransport, self.reportingFactory
         )
-        self.reportingFactory.inheritedPort.startReading()
+        inheritedPort.startReading()
+        inheritedPort.reportStatus("0")
 
 
     def stopService(self):
@@ -165,6 +166,14 @@
         self.maxRequests = maxRequests
 
 
+    def startService(self):
+        """
+        Start up multiservice, then start up the dispatcher.
+        """
+        super(ConnectionLimiter, self).startService()
+        self.dispatcher.startDispatching()
+
+
     def addPortService(self, description, port, interface, backlog):
         """
         Add a L{MaxAcceptTCPServer} to bind a TCP port to a socket description.
@@ -186,13 +195,22 @@
         Determine a subprocess socket's status from its previous status and a
         status message.
         """
-        if message == '-':
-            result = self.intWithNoneAsZero(previousStatus) - 1
-            # A connection has gone away in a subprocess; we should start
-            # accepting connections again if we paused (see
-            # newConnectionStatus)
-            for f in self.factories:
-                f.myServer.myPort.startReading()
+        if message in ('-', '0'):
+            if message == '-':
+                # A connection has gone away in a subprocess; we should start
+                # accepting connections again if we paused (see
+                # newConnectionStatus)
+                result = self.intWithNoneAsZero(previousStatus) - 1
+            else:
+                # A new process just started accepting new connections; zero
+                # out its expected load.
+                result = 0
+            # If load has indeed decreased (i.e. in any case except 'a new,
+            # idle process replaced an old, idle process'), then start
+            # listening again.
+            if result < previousStatus:
+                for f in self.factories:
+                    f.myServer.myPort.startReading()
         else:
             # '+' is just an acknowledgement of newConnectionStatus, so we can
             # ignore it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100421/e9a02ab2/attachment.html>


More information about the calendarserver-changes mailing list