[CalendarServer-changes] [5505] CalendarServer/branches/users/wsanchez/deployment/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 21 18:15:12 PDT 2010


Revision: 5505
          http://trac.macosforge.org/projects/calendarserver/changeset/5505
Author:   glyph at apple.com
Date:     2010-04-21 18:15:11 -0700 (Wed, 21 Apr 2010)
Log Message:
-----------
pull in r5504 to deployment

Revision Links:
--------------
    http://trac.macosforge.org/projects/calendarserver/changeset/5504

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/cluster.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/sendfdport.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/test/test_tap.py

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/cluster.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/cluster.py	2010-04-22 01:11:22 UTC (rev 5504)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/cluster.py	2010-04-22 01:15:11 UTC (rev 5505)
@@ -66,7 +66,7 @@
 
     def __init__(self, twistd, tapname, configFile, id,
                  interfaces, port, sslPort,
-                 inheritFDs=None, inheritSSLFDs=None, dispatcher=None):
+                 inheritFDs=None, inheritSSLFDs=None, metaSocket=None):
 
         self.twistd = twistd
 
@@ -86,9 +86,7 @@
                 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):
@@ -96,22 +94,13 @@
             return '%s-%s' % (self.prefix, self.ports[0])
         elif self.sslPorts is not None:
             return '%s-%s' % (self.prefix, self.sslPorts[0])
-        elif self.inheritFDs or self.inheritSSLFDs or self.dispatcher:
+        elif self.inheritFDs or self.inheritSSLFDs or self.metaSocket:
             return '%s-%s' % (self.prefix, self.id)
 
         raise ConfigurationError(
             "Can't create TwistdSlaveProcess without a TCP Port")
 
 
-    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)
@@ -119,8 +108,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
@@ -180,11 +169,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
@@ -199,7 +186,7 @@
         if ssl and self.sslPorts is not None:
             port = self.sslPorts
 
-        if self.inheritFDs or self.inheritSSLFDs or self.dispatcher:
+        if self.inheritFDs or self.inheritSSLFDs or self.metaSocket:
             port = [self.id]
 
         if port is None:
@@ -499,7 +486,7 @@
         if config.UseMetaFD:
             port = None
             sslPort = None
-            extraArgs = dict(dispatcher=cl.dispatcher)
+            extraArgs = dict(metaSocket=cl.dispatcher.addSocket())
         else:
             extraArgs = dict(inheritFDs=inheritFDs,
                              inheritSSLFDs=inheritSSLFDs)

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py	2010-04-22 01:11:22 UTC (rev 5504)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py	2010-04-22 01:15:11 UTC (rev 5505)
@@ -18,8 +18,6 @@
 from twisted.internet.tcp import Server
 from twisted.application.internet import TCPServer
 
-from twisted.internet import reactor
-
 from twisted.application.service import MultiService, Service
 
 from twisted.web2.channel.http import HTTPFactory
@@ -61,10 +59,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):
@@ -152,6 +151,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{TCPServer} to bind a TCP port to a socket description.
@@ -175,13 +182,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.serverService._port.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.

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/sendfdport.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/sendfdport.py	2010-04-22 01:11:22 UTC (rev 5504)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/sendfdport.py	2010-04-22 01:15:11 UTC (rev 5505)
@@ -200,6 +200,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
@@ -211,7 +219,6 @@
         """
         i, o = socketpair(AF_UNIX, SOCK_DGRAM)
         a = _SubprocessSocket(self, o)
-        a.startReading()
         self._subprocessSockets.append(a)
         return i
 

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/test/test_tap.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/test/test_tap.py	2010-04-22 01:11:22 UTC (rev 5504)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/test/test_tap.py	2010-04-22 01:15:11 UTC (rev 5505)
@@ -887,7 +887,7 @@
             port          = None,
             sslPort       = None,
             interfaces = '127.0.0.1',
-            dispatcher = FakeDispatcher()
+            metaSocket = FakeDispatcher().addSocket()
         )
 
         dspm.addProcessObject(slave, {})
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100421/ff41dbec/attachment-0001.html>


More information about the calendarserver-changes mailing list