[Erp5-report] r14209 - in /erp5/trunk/utils/oood: dispatcher.py worker.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Apr 25 02:12:18 CEST 2007
Author: bartek
Date: Wed Apr 25 02:12:16 2007
New Revision: 14209
URL: http://svn.erp5.org?rev=14209&view=rev
Log:
lots of introspection information - timing workers and server, counting requests for the server and for each worker, everything displayed in pool status info
Modified:
erp5/trunk/utils/oood/dispatcher.py
erp5/trunk/utils/oood/worker.py
Modified: erp5/trunk/utils/oood/dispatcher.py
URL: http://svn.erp5.org/erp5/trunk/utils/oood/dispatcher.py?rev=14209&r1=14208&r2=14209&view=diff
==============================================================================
--- erp5/trunk/utils/oood/dispatcher.py (original)
+++ erp5/trunk/utils/oood/dispatcher.py Wed Apr 25 02:12:16 2007
@@ -61,6 +61,8 @@
TIMEOUT = 54
BAD_DOCUMENT = 55
+def formatTime(t):
+ return time.strftime('%H:%M:%S', time.gmtime(t))
class MySerw(ThreadingMixIn, SimpleXMLRPCServer):
@@ -109,10 +111,15 @@
# init locks
self.emergency_restart_lock = threading.Lock()
# initialize
+ self.creation_time = int(time.time())
+ self.counter = 0
+ self.restart_count = -1
self.initialize()
def initialize(self):
# cancel all waiting timers
+ self.start_time = int(time.time())
+ self.restart_count += 1
Log.info('initializing...')
for thr in threading.enumerate():
try:
@@ -285,22 +292,29 @@
return s
def poolStatus(self):
+ current_time = int(time.time())
s = ''
- line = '%-5s|%-10s|%-30s|\n' % ('idx', 'busy', 'file')
+ s += 'Server up: %s\n' % formatTime(current_time - self.creation_time)
+ s += 'Restarts: %s\n' % self.restart_count
+ s += 'Up since last restart: %s\n' % formatTime(current_time - self.start_time)
+ s += 'Processed requests: %s\n' % self.counter
+ s += '\n'
+ line = '%-5s|%-8s|%-5s|%-5s|%-30s|\n' % ('idx', 'up', 'count', 'busy', 'file')
s += line
- line = '%s+%s+%s\n' % ('-'*5, '-'*10, '-'*30)
+ line = '%s+%s+%s+%s+%s\n' % ('-'*5, '-'*8, '-'*5, '-'*5, '-'*30)
s += line
worker_index_list = pool.inst.keys()
worker_index_list.sort()
for idx in worker_index_list:
worker = pool.inst[idx]
if worker is None:
- busy = 'xxxx'
- file = 'xxxx'
+ up = count = busy = file = 'xxxx'
else:
- busy = worker.busy and 'busy' or '-'
+ busy = worker.busytime or '-'
+ up = formatTime(worker.uptime)
+ count = worker.counter
file = getattr(worker, 'fileUrl', None) or '-'
- line = '%-5s|%-10s|%-30s|\n' % (idx, busy, file)
+ line = '%-5s|%-8s|%-5s|%-5s|%-30s|\n' % (idx, up, count, busy, file)
s += line
return s
@@ -343,8 +357,10 @@
self._zipResult(kw)
else:
kw['data'] = base64.encodestring(open(self._mkName(kw['newfilename'])).read())
+ self.counter += 1
return kw
else:
+ self.counter += 1
return method(*a)
def _zipResult(self, kw):
Modified: erp5/trunk/utils/oood/worker.py
URL: http://svn.erp5.org/erp5/trunk/utils/oood/worker.py?rev=14209&r1=14208&r2=14209&view=diff
==============================================================================
--- erp5/trunk/utils/oood/worker.py (original)
+++ erp5/trunk/utils/oood/worker.py Wed Apr 25 02:12:16 2007
@@ -90,6 +90,34 @@
self.cwd = systemPathToFileUrl(config.oood_home)
self._reset()
self._generateFuncs()
+ self.creation_time = int(time.time())
+ self.start_time = 0
+ self.counter = 0
+
+ def __setattr__(self, name, value):
+ """
+ When the worker is flagged as busy, we start measuring
+ its "busytime"
+ """
+ if name == 'busy':
+ if value:
+ self.start_time = int(time.time())
+ else:
+ self.start_time = 0
+ object.__setattr__(self, name, value)
+
+ def __getattribute__(self, name):
+ """
+ Used to measure uptime and busytime
+ """
+ current_time = int(time.time())
+ if name == 'uptime':
+ return current_time - self.creation_time
+ if name == 'busytime':
+ if self.start_time == 0:
+ return 0
+ return current_time - self.start_time
+ return object.__getattribute__(self, name)
def setBusy(self):
"""
@@ -242,6 +270,7 @@
if not self.doc:
Log.error('[worker] ' + fname + ' was loaded into OpenOffice')
raise lib.NotLoaded(self.fileUrl)
+ self.counter += 1
def _saveFile(self):
self.doc.store()
More information about the Erp5-report
mailing list