[Zodb-checkins] CVS: StandaloneZODB/ZEO - StorageServer.py:1.28.2.4 zrpc.py:1.18.2.3

Jeremy Hylton jeremy@zope.com
Tue, 2 Oct 2001 19:16:03 -0400


Update of /cvs-repository/StandaloneZODB/ZEO
In directory cvs.zope.org:/tmp/cvs-serv29131

Modified Files:
      Tag: zeo-1_0-branch
	StorageServer.py zrpc.py 
Log Message:
Be careful about memory overhead of logging!

The various logging calls did a lot of string formatting work that
could consume very large amounts of memory.  The worst case analysis
is a store() call with a multi-megabyte pickle:  We created a repr of
the pickle then performed several string operations that copied the
repr.

The new code goes out of its way to avoid copying large strings.

Regardless: ZEO should be substantially faster when run under 
python -O.


=== StandaloneZODB/ZEO/StorageServer.py 1.28.2.3 => 1.28.2.4 ===
 from ZEO import trigger
 from ZEO import asyncwrap
+from types import StringType
 
 class StorageServerError(POSException.StorageError): pass
 
 max_blather=120
 def blather(*args):
-    m=string.join(map(str,args))
-    if len(m) > max_blather: m=m[:max_blather]+' ...'
+    accum = []
+    total_len = 0
+    for arg in args:
+        if not isinstance(arg, StringType):
+            arg = str(arg)
+        accum.append(arg)
+        total_len = total_len + len(arg)
+        if total_len >= max_blather:
+            break
+    m = string.join(accum)
+    if len(m) > max_blather: m = m[:max_blather] + ' ...'
     LOG('ZEO Server', TRACE, m)
 
 
@@ -258,7 +268,12 @@
     def message_input(self, message,
                       dump=dump, Unpickler=Unpickler, StringIO=StringIO,
                       None=None):
-        if __debug__: blather('message_input', id(self), `message`)
+        if __debug__:
+            if len(message) > max_blather:
+                tmp = `message[:max_blather]`
+            else:
+                tmp = `message`
+            blather('message_input', id(self), tmp)
 
         if self.__storage is None:
             # This is the first communication from the client
@@ -276,7 +291,9 @@
             args=unpickler.load()
             
             name, args = args[0], args[1:]
-            if __debug__: blather('call %s: %s%s' % (id(self), name, `args`))
+            if __debug__:
+                apply(blather,
+                      ("call", id(self), ":", name,) + args)
                 
             if not storage_method(name):
                 raise 'Invalid Method Name', name
@@ -294,7 +311,8 @@
             self.return_error(sys.exc_info()[0], sys.exc_info()[1])
             return
 
-        if __debug__: blather("%s R: %s" % (id(self), `r`))
+        if __debug__:
+            blather("%s R: %s" % (id(self), `r`))
             
         r=dump(r,1)            
         self.message_output('R'+r)
@@ -303,7 +321,8 @@
         if type(err_value) is not type(self):
             err_value = err_type, err_value
 
-        if __debug__: blather("%s E: %s" % (id(self), `err_value`))
+        if __debug__:
+            blather("%s E: %s" % (id(self), `err_value`))
                     
         try: r=dump(err_value, 1)
         except:


=== StandaloneZODB/ZEO/zrpc.py 1.18.2.2 => 1.18.2.3 ===
     def message_input(self, m):
         if self._debug:
-            md=`m`
-            if len(m) > 60: md=md[:60]+' ...'
+            if len(m) > 60:
+                md = repr(m[:60]) + ' ...'
+            else:
+                md = repr(m)
             LOG(self._debug, TRACE, 'message_input %s' % md)
 
         c=m[:1]