[CalendarServer-changes] [2423] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 15 10:29:39 PDT 2008
Revision: 2423
http://trac.macosforge.org/projects/calendarserver/changeset/2423
Author: dreid at apple.com
Date: 2008-05-15 10:29:38 -0700 (Thu, 15 May 2008)
Log Message:
-----------
Make the ThreadPoolSize configurable, and resize the threadpool on SIGHUP. Also use the threadpool to read cache token xattrs.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/cache.py
CalendarServer/trunk/twistedcaldav/config.py
CalendarServer/trunk/twistedcaldav/tap.py
CalendarServer/trunk/twistedcaldav/test/test_cache.py
Modified: CalendarServer/trunk/twistedcaldav/cache.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/cache.py 2008-05-15 00:23:15 UTC (rev 2422)
+++ CalendarServer/trunk/twistedcaldav/cache.py 2008-05-15 17:29:38 UTC (rev 2423)
@@ -31,6 +31,7 @@
from twisted.web2.dav.xattrprops import xattrPropertyStore
+from twisted.internet.threads import deferToThread
from twistedcaldav.log import LoggingMixIn
@@ -132,35 +133,19 @@
@return: An L{IResponse} or C{None} if the response has not been cached.
"""
- def _returnRequest(requestBody):
+ def _getTokens(pURI, rURI):
+ pToken = self._tokenForURI(pURI)
+ uToken = self._tokenForURI(rURI)
- if requestBody is not None:
- request.stream = MemoryStream(requestBody)
- request.stream.doStartReading = None
+ return (pToken, uToken)
- principalURI = self._principalURI(request.authnUser)
- key = (request.method,
- request.uri,
- principalURI,
- request.headers.getHeader('depth'),
- hash(requestBody))
+ def _checkTokens((newPrincipalToken, newURIToken), key):
+ (principalToken,
+ uriToken,
+ accessTime,
+ response) = self._responses[key]
- self.log_debug("Checking cache for: %r" % (key,))
-
- request.cacheKey = key
-
- if key not in self._responses:
- self.log_debug("Not in cache: %r" % (key,))
- self.log_debug(" Cache Keys: %r" % (
- self._responses.keys(),))
- return None
-
- principalToken, uriToken, accessTime, response = self._responses[key]
-
- newPrincipalToken = self._tokenForURI(principalURI)
- newURIToken = self._tokenForURI(request.uri)
-
if newPrincipalToken != principalToken:
self.log_debug("Principal token changed on %r from %r to %r" % (
key,
@@ -193,6 +178,36 @@
return responseObj
+
+ def _returnRequest(requestBody):
+
+ if requestBody is not None:
+ request.stream = MemoryStream(requestBody)
+ request.stream.doStartReading = None
+
+ principalURI = self._principalURI(request.authnUser)
+
+ key = (request.method,
+ request.uri,
+ principalURI,
+ request.headers.getHeader('depth'),
+ hash(requestBody))
+
+ self.log_debug("Checking cache for: %r" % (key,))
+
+ request.cacheKey = key
+
+ if key not in self._responses:
+ self.log_debug("Not in cache: %r" % (key,))
+ return None
+
+ d1 = deferToThread(_getTokens,
+ principalURI,
+ request.uri)
+ d1.addCallback(_checkTokens, key)
+
+ return d1
+
d = allDataFromStream(request.stream)
d.addCallback(_returnRequest)
return d
Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py 2008-05-15 00:23:15 UTC (rev 2422)
+++ CalendarServer/trunk/twistedcaldav/config.py 2008-05-15 17:29:38 UTC (rev 2423)
@@ -199,6 +199,8 @@
"Enabled": False,
"BaseDirectory": "/tmp/stats",
},
+
+ "ThreadPoolSize": 10,
}
class Config (object):
Modified: CalendarServer/trunk/twistedcaldav/tap.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/tap.py 2008-05-15 00:23:15 UTC (rev 2422)
+++ CalendarServer/trunk/twistedcaldav/tap.py 2008-05-15 17:29:38 UTC (rev 2423)
@@ -19,6 +19,8 @@
from zope.interface import implements
+from twisted.internet import reactor
+
from twisted.python.log import FileLogObserver
from twisted.python.usage import Options, UsageError
from twisted.python.reflect import namedClass
@@ -718,6 +720,8 @@
# Change log level back to what it was before
setLogLevelForNamespace(None, oldLogLevel)
+ reactor.suggestThreadPoolSize(config.ThreadPoolSize)
+
return service
makeService_Combined = makeService_Combined
@@ -758,8 +762,13 @@
log.error("SIGHUP recieved at %s" % (location(frame),))
# Reload the config file
+ log.info("Reloading configuration file")
config.reload()
+ log.info("Suggesting size for the reactor threadpool: %r" % (
+ config.ThreadPoolSize))
+ reactor.suggestThreadPoolSize(config.ThreadPoolSize)
+
signal.signal(signal.SIGHUP, sighup_handler)
#def sigusr1_handler(num, frame):
Modified: CalendarServer/trunk/twistedcaldav/test/test_cache.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_cache.py 2008-05-15 00:23:15 UTC (rev 2422)
+++ CalendarServer/trunk/twistedcaldav/test/test_cache.py 2008-05-15 17:29:38 UTC (rev 2423)
@@ -55,6 +55,7 @@
self.stream = MemoryStream(body)
+
class StubResponse(object):
def __init__(self, code, headers, body):
self.code = code
@@ -135,6 +136,7 @@
d.addCallback(self.assertEquals, None)
return d
+
def test_getResponseForRequestInCache(self):
d = self.rc.getResponseForRequest(StubRequest(
'PROPFIND',
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080515/792578ac/attachment.htm
More information about the calendarserver-changes
mailing list