[CalendarServer-changes] [15500] CalendarServer/trunk/calendarserver

source_changes at macosforge.org source_changes at macosforge.org
Mon Apr 4 14:02:51 PDT 2016


Revision: 15500
          http://trac.calendarserver.org//changeset/15500
Author:   cdaboo at apple.com
Date:     2016-04-04 14:02:51 -0700 (Mon, 04 Apr 2016)
Log Message:
-----------
Don't run the SystemMonitor when stats socket is not in use. Avoids creating a task that runs once a second and uses excessive CPU on low traffic servers.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/accesslog.py
    CalendarServer/trunk/calendarserver/test/test_accesslog.py

Modified: CalendarServer/trunk/calendarserver/accesslog.py
===================================================================
--- CalendarServer/trunk/calendarserver/accesslog.py	2016-04-02 14:39:29 UTC (rev 15499)
+++ CalendarServer/trunk/calendarserver/accesslog.py	2016-04-04 21:02:51 UTC (rev 15500)
@@ -376,6 +376,11 @@
         Update stats
         """
 
+        # Only use the L{SystemMonitor} when stats socket is in use
+        if not config.Stats.EnableUnixStatsSocket and not config.Stats.EnableTCPStatsSocket:
+            return
+
+        # Initialize a L{SystemMonitor} on the first call
         if self.systemStats is None:
             self.systemStats = SystemMonitor()
 
@@ -395,6 +400,11 @@
         Return the stats
         """
 
+        # Only use the L{SystemMonitor} when stats socket is in use
+        if not config.Stats.EnableUnixStatsSocket and not config.Stats.EnableTCPStatsSocket:
+            return {}
+
+        # Initialize a L{SystemMonitor} on the first call
         if self.systemStats is None:
             self.systemStats = SystemMonitor()
 

Modified: CalendarServer/trunk/calendarserver/test/test_accesslog.py
===================================================================
--- CalendarServer/trunk/calendarserver/test/test_accesslog.py	2016-04-02 14:39:29 UTC (rev 15499)
+++ CalendarServer/trunk/calendarserver/test/test_accesslog.py	2016-04-04 21:02:51 UTC (rev 15500)
@@ -18,6 +18,7 @@
 from calendarserver.accesslog import SystemMonitor, \
     RotatingFileAccessLoggingObserver
 from twistedcaldav.stdconfig import config as stdconfig
+from twistedcaldav.config import config
 
 hasattr(stdconfig, "Servers")   # Quell pyflakes
 
@@ -42,6 +43,47 @@
         self.assertNotEqual(monitor.items["cpu count"], 0)
 
 
+    def test_disableSystemMonitor(self):
+        """
+        L{SystemMonitor} is not created when stats socket not in use.
+        """
+
+        # Disabled
+        self.patch(config.Stats, "EnableUnixStatsSocket", False)
+        self.patch(config.Stats, "EnableTCPStatsSocket", False)
+
+        logger = RotatingFileAccessLoggingObserver("")
+        self.assertTrue(logger.systemStats is None)
+
+        logger.logStats({})
+        self.assertTrue(logger.systemStats is None)
+
+        logger.getStats()
+        self.assertTrue(logger.systemStats is None)
+
+        # Enabled
+        self.patch(config.Stats, "EnableUnixStatsSocket", True)
+        self.patch(config.Stats, "EnableTCPStatsSocket", False)
+
+        logger = RotatingFileAccessLoggingObserver("")
+        self.assertTrue(logger.systemStats is None)
+
+        logger.logStats({})
+        self.assertTrue(logger.systemStats is not None)
+        logger.systemStats.stop()
+
+        # Enabled
+        self.patch(config.Stats, "EnableUnixStatsSocket", False)
+        self.patch(config.Stats, "EnableTCPStatsSocket", True)
+
+        logger = RotatingFileAccessLoggingObserver("")
+        self.assertTrue(logger.systemStats is None)
+
+        logger.logStats({})
+        self.assertTrue(logger.systemStats is not None)
+        logger.systemStats.stop()
+
+
     def test_unicodeLog(self):
         """
         Make sure L{RotatingFileAccessLoggingObserver} handles non-ascii data properly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160404/2fb4a72a/attachment.html>


More information about the calendarserver-changes mailing list