[ZODB-Dev] MemoryLeaks using multiple DBs ?
Heiko Hees
heiko.hees@brainbot.com
Thu, 08 Aug 2002 17:23:18 +0200
Hi,
i am developing a webservice and want to use ZODB with Webware. I
planned to use a seperate FileStorage for each user. Unfortunally it
seems like ZODB doesn't free Storage when connections are closed.
The following script opens and closes 10 seperate connections and writes
10MB of data into each. Memoryusage goes up to 107MB on my system :-(
I am using Python 2.2.1 and StandaloneZODB 1.0 on Linux.
Any thoughts/alternatives or suggestions?
Regards
Heiko Hees
#!/usr/bin/python
import ZODB, sys, time, types
from ZODB import FileStorage, DB
from BTrees.IOBTree import IOBTree
def get_refcounts():
d = {}
sys.modules
# collect all classes
for m in sys.modules.values():
for sym in dir(m):
o = getattr (m, sym)
if type(o) is types.ClassType:
d[o] = sys.getrefcount (o)
# sort by refcount
pairs = map (lambda x: (x[1],x[0]), d.items())
pairs.sort()
pairs.reverse()
return pairs
def print_top(num):
for n, c in get_refcounts()[:1000]:
print '%10d %s' % (n, c.__name__)
if __name__ == '__main__':
import os
try:
path = sys.argv[1]
assert(os.path.isdir(path))
except:
print "usage:%s dir" % sys.argv[0]
sys.exit(10)
for i in range(10): # open, write, close 10 seperate storages
# open fs,db,connection -> write data -> close
fs = FileStorage.FileStorage("%s/%d" % (path,i))
db = DB(fs)
connection = db.open()
root = connection.root()
root['data'] = IOBTree()
for i in range(1024 * 10): # create 10MB data in storage
root['data'][i] = "x"*1024
get_transaction().commit()
#root['data']._p_jar.cacheGC()
connection.close()
db.close()
fs.close()
# check whats left
print_top(1000)
# reports:
# 27 Connection
# ...
# 11 FileStorage
# ...
# 7 DB
print "check size w/o user:"
# top says:
# PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
# 734 heiko 9 0 107M 107M 1364 S 0.0 43.2 0:18
zodbMemTest.py
time.sleep(1000)
--
brainbot technologies ag
schwalbacherstr. 74 65183 wiesbaden . germany
vox +49 611 238505-0 fax ++49 611 238505-1
http://brainbot.com/ mailto:heiko@brainbot.com