[CalendarServer-changes] [2416] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed May 14 10:59:28 PDT 2008


Revision: 2416
          http://trac.macosforge.org/projects/calendarserver/changeset/2416
Author:   dreid at apple.com
Date:     2008-05-14 10:59:28 -0700 (Wed, 14 May 2008)

Log Message:
-----------
Add a log message when cache expiration happens, also add a currently failing even though pessimistic benchmark for cache expiration

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/cache.py
    CalendarServer/trunk/twistedcaldav/test/test_cache.py

Modified: CalendarServer/trunk/twistedcaldav/cache.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/cache.py	2008-05-14 00:13:33 UTC (rev 2415)
+++ CalendarServer/trunk/twistedcaldav/cache.py	2008-05-14 17:59:28 UTC (rev 2416)
@@ -83,9 +83,7 @@
         if cacheSize is not None:
             self.CACHE_SIZE = cacheSize
 
-        self._accessTimes = None
 
-
     def _tokenForURI(self, uri):
         """
         Get a property store for the given C{uri}.
@@ -242,6 +240,9 @@
                         leastRecentlyUsedTime = cacheEntry[2]
                         leastRecentlyUsedKey = cacheKey
 
+                self.log_warn("Expiring from cache: %r" % (
+                        leastRecentlyUsedKey,))
+
                 del self._responses[leastRecentlyUsedKey]
 
 

Modified: CalendarServer/trunk/twistedcaldav/test/test_cache.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_cache.py	2008-05-14 00:13:33 UTC (rev 2415)
+++ CalendarServer/trunk/twistedcaldav/test/test_cache.py	2008-05-14 17:59:28 UTC (rev 2416)
@@ -103,16 +103,20 @@
 
         self.expected_response = (200, Headers({}), "Foo")
 
-        self.rc._responses[(
+        expected_key = (
                 'PROPFIND',
                 '/calendars/users/cdaboo/',
                 '/principals/users/cdaboo/',
                 1,
                 hash('foobar'),
-                )] = (
+                )
+
+        self.rc._responses[expected_key] = (
             'principalToken0', 'uriToken0', 0, self.expected_response)
 
+        self.rc._accessList = [expected_key]
 
+
     def assertResponse(self, response, expected):
         self.assertEquals(response.code, expected[0])
         self.assertEquals(response.headers, expected[1])
@@ -252,3 +256,39 @@
 
         d.addCallback(_assertResponse)
         return d
+
+
+    def test_cacheExpirationBenchmark(self):
+        self.rc.CACHE_SIZE = 70000
+        import time
+
+        self.rc._responses = {}
+        self.rc._accessList = []
+
+        for x in xrange(0, self.rc.CACHE_SIZE):
+            req = StubRequest('PROPFIND',
+                              '/principals/users/user%d' % (x,),
+                              '/principals/users/user%d' % (x,))
+            self.rc._responses[req] = (
+                'pTokenUser%d' % (x,), 'rTokenUser%d' % (x,), 0,
+                (200, {}, 'foobar'))
+
+            self.rc._accessList.append(req)
+
+        def assertTime(result, startTime):
+            duration = time.time() - startTime
+
+            self.failUnless(
+                duration < 0.01,
+                "Took to long to add to the cache: %r" % (duration,))
+
+        startTime = time.time()
+
+        d = self.rc.cacheResponseForRequest(
+            StubRequest('PROPFIND',
+                        '/principals/users/dreid/',
+                        '/principals/users/dreid/'),
+            StubResponse(200, {}, 'Foobar'))
+
+        d.addCallback(assertTime, startTime)
+        return d

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080514/023cb538/attachment.html


More information about the calendarserver-changes mailing list