[CalendarServer-changes] [1398] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 15 14:22:26 PDT 2007
Revision: 1398
http://trac.macosforge.org/projects/calendarserver/changeset/1398
Author: dreid at apple.com
Date: 2007-03-15 14:22:25 -0700 (Thu, 15 Mar 2007)
Log Message:
-----------
Introduce dependency on ctypes, have ./run download if it isn't available (ctypes is in the stdlib as of python 2.5)
Make 0 the default ProcessCount in config.py
Add getNCPU implementation for darwin and linux2
If the ProcessCount is 0 try to autodetect the number of CPUs then fallback to one.
Modified Paths:
--------------
CalendarServer/trunk/run
CalendarServer/trunk/twistedcaldav/cluster.py
CalendarServer/trunk/twistedcaldav/config.py
Added Paths:
-----------
CalendarServer/trunk/twistedcaldav/util.py
Modified: CalendarServer/trunk/run
===================================================================
--- CalendarServer/trunk/run 2007-03-15 18:35:56 UTC (rev 1397)
+++ CalendarServer/trunk/run 2007-03-15 21:22:25 UTC (rev 1398)
@@ -465,6 +465,20 @@
fi;
#
+# ctypes
+#
+
+if ! py_have_module ctypes; then
+ ctypes="${top}/ctypes-1.0.0"
+
+ www_get "ctypes" "${ctypes}" http://easynews.dl.sourceforge.net/sourceforge/ctypes/ctypes-1.0.0.tar.gz;
+ py_build "ctypes" "${ctypes}" true;
+ py_install "ctypes" "${ctypes}";
+
+ export PYTHONPATH="${PYTHONPATH}:${ctypes}/build/${py_platform_libdir}";
+fi;
+
+#
# Twisted
#
Modified: CalendarServer/trunk/twistedcaldav/cluster.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/cluster.py 2007-03-15 18:35:56 UTC (rev 1397)
+++ CalendarServer/trunk/twistedcaldav/cluster.py 2007-03-15 21:22:25 UTC (rev 1398)
@@ -26,6 +26,8 @@
from twisted.scripts.mktap import getid
from twistedcaldav.config import config
+from twistedcaldav.util import getNCPU
+
serviceTemplate = """
<service name="%(name)s">
<listen ip="%(bindAddress)s:%(port)s" />
@@ -109,6 +111,18 @@
if not config.MultiProcess['LoadBalancer']['Enabled']:
bindAddress = config.BindAddresses
+ if config.MultiProcess['ProcessCount'] == 0:
+ try:
+ config.MultiProcess['ProcessCount'] = getNCPU()
+ log.msg("%d processors found, configuring %d processes." % (
+ config.MultiProcess['ProcessCount'],
+ config.MultiProcess['ProcessCount']))
+
+ except NotImplementedError, err:
+ log.msg('Could not autodetect number of CPUs:')
+ log.msg(err)
+ config.MultiProcess['ProcessCount'] = 1
+
for p in xrange(0, config.MultiProcess['ProcessCount']):
if int(config.MultiProcess['ProcessCount']) > 1:
port += 1
Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py 2007-03-15 18:35:56 UTC (rev 1397)
+++ CalendarServer/trunk/twistedcaldav/config.py 2007-03-15 21:22:25 UTC (rev 1398)
@@ -123,7 +123,7 @@
"GroupName": "daemon",
"ProcessType": "Slave",
"MultiProcess": {
- "ProcessCount": 4,
+ "ProcessCount": 0,
"LoadBalancer": {
"Enabled": True,
"Scheduler": "LeastConnections",
Added: CalendarServer/trunk/twistedcaldav/util.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/util.py (rev 0)
+++ CalendarServer/trunk/twistedcaldav/util.py 2007-03-15 21:22:25 UTC (rev 1398)
@@ -0,0 +1,63 @@
+##
+# Copyright (c) 2007 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# DRI: David Reid, dreid at apple.com
+##
+
+import sys
+
+try:
+ from ctypes import *
+ import ctypes.util
+ hasCtypes = True
+except ImportError:
+ hasCtypes = False
+
+if sys.platform == 'darwin' and hasCtypes:
+ from ctypes import *
+ import ctypes.util
+
+ libc = cdll.LoadLibrary(ctypes.util.find_library('libc'))
+
+ def getNCPU():
+ ncpu = c_int(0)
+
+ size = c_int(sizeof(ncpu))
+
+ libc.sysctlbyname('hw.ncpu',
+ c_voidp(addressof(ncpu)),
+ addressof(size),
+ None, 0)
+
+ return int(ncpu.value)
+
+elif sys.platform == 'linux2' and hasCtypes:
+ from ctypes import *
+ import ctypes.util
+
+ libc = cdll.LoadLibrary(ctypes.util.find_library('libc'))
+
+ def getNCPU():
+ return libc.get_nprocs()
+
+else:
+ def getNCPU():
+ if not hasCtypes:
+ msg = "without ctypes"
+ else:
+ msg = ""
+
+ raise NotImplementedError(
+ "getNCPU not supported on %s %s" % (sys.platform, msg))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070315/40f11e16/attachment.html
More information about the calendarserver-changes
mailing list