[Zope-CVS] CVS: Products/FileCacheManager/tests - stresstest.py:1.3
Jens Vagelpohl
jens at dataflake.org
Tue Aug 17 10:38:40 EDT 2004
Update of /cvs-repository/Products/FileCacheManager/tests
In directory cvs.zope.org:/tmp/cvs-serv4421/tests
Modified Files:
stresstest.py
Log Message:
- implemented threaded readers for stresstest and it runs fine
=== Products/FileCacheManager/tests/stresstest.py 1.2 => 1.3 ===
--- Products/FileCacheManager/tests/stresstest.py:1.2 Tue Aug 17 05:17:47 2004
+++ Products/FileCacheManager/tests/stresstest.py Tue Aug 17 10:38:40 2004
@@ -13,13 +13,18 @@
##############################################################################
import os
+import threading
+import time
import ZODB
from ZODB.MappingStorage import MappingStorage
+from ZPublisher.Iterators import filestream_iterator
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.User import UnrestrictedUser
from Globals import package_home
+from Testing import makerequest
+from OFS.Application import Application
from OFS.Folder import Folder, manage_addFolder
from OFS.Image import manage_addImage
from Products.PythonScripts.PythonScript import manage_addPythonScript
@@ -47,6 +52,9 @@
PYSCRIPT_PARAMS = ''
PYSCRIPT_BODY = """
"""
+READERS=10
+WRITERS=0
+ITERATIONS = 100
# End tweakable items
######################
@@ -57,10 +65,9 @@
db = ZODB.DB(s)
jar = db.open()
app_root = jar.root()
- folder = Folder('testing')
- app_root['testing'] = folder
+ app_root['app'] = Application()
global ROOT
- ROOT = app_root.get('testing')
+ ROOT = app_root.get('app')
# Set up a Security Manager so we do everything as a manager
newSecurityManager(None, UnrestrictedUser('manager', '', ['Manager'], []))
@@ -114,14 +121,143 @@
for name in dirs:
os.rmdir(os.path.join(root, name))
-def stress():
- print ROOT.objectIds()
+class ReadStresser(threading.Thread):
+ """ Objects that simulate read or write access to the cached resources """
+ def __init__(self, root, paths, iterations):
+ self.root = root
+ self.paths = paths
+ self.iterations = iterations
+ self.finished = 0
+ threading.Thread.__init__(self)
+
+ def run(self):
+ for i in range(self.iterations):
+ for path in self.paths:
+ root = makerequest.makerequest(self.root)
+ ob = root.unrestrictedTraverse(path)
+ print '.',
+ sys.stdout.flush()
+ data = ob.index_html(root.REQUEST, root.REQUEST['RESPONSE'])
+ original_data = IMAGES.get(ob.getId())
+
+ if isinstance(data, filestream_iterator):
+ data_str = ''
+ while 1:
+ try:
+ data_str = data_str + data.next()
+ except StopIteration:
+ break
+ data = data_str
+
+ if not data:
+ print 'N',
+ self.stdout.flush()
+ if data != original_data:
+ print 'E',
+ sys.stdout.flush()
+ if ob.ZCacheable_get(default=None) is None:
+ print 'C',
+ sys.stdout.flush()
+
+ self.finished = 1
+
+ def isFinished(self):
+ return self.finished
+
+
+class WriteStresser(threading.Thread):
+ """ Objects that simulate read or write access to the cached resources """
+ def __init__(self, root, paths, iterations):
+ self.root = root
+ self.paths = paths
+ sef.iterations = iterations
+ self.finished = 0
+ threading.Thread.__init__(self)
+
+ def run(self):
+ self.finished = 1
+
+ def isFinished(self):
+ return self.finished
+
+def numActive(threads):
+ count = 0
+ for thread in threads:
+ if not thread.isFinished():
+ count += 1
+
+ return count
+def stress():
+ readers = []
+ writers = []
+ paths = []
+
+ for id in ROOT.objectIds(['Folder']):
+ for img_file in IMAGES.keys():
+ paths.append('%s/%s' % (id, img_file))
+
+###
+# for i in range(ITERATIONS):
+# for path in paths:
+# root = makerequest.makerequest(ROOT)
+# ob = root.unrestrictedTraverse(path)
+# print '.',
+# sys.stdout.flush()
+# data = ob.index_html(root.REQUEST, root.REQUEST['RESPONSE'])
+#
+# if isinstance(data, filestream_iterator):
+# data_str = ''
+# while 1:
+# try:
+# data_str = data_str + data.next()
+# except StopIteration:
+# break
+#
+# data = data_str
+#
+# if not data:
+# print 'N',
+# self.stdout.flush()
+# if data != IMAGES.get(ob.getId()):
+# print 'E',
+# sys.stdout.flush()
+# if ob.ZCacheable_get(default=None) is None:
+# print 'C',
+# sys.stdout.flush()
+###
+
+ for i in range(READERS):
+ thread = ReadStresser(ROOT, paths, ITERATIONS)
+ readers.append(thread)
+
+ for i in range(WRITERS):
+ thread = WriteStresser(ROOT, paths, ITERATIONS)
+ writers.append(thread)
+
+ for reader in readers:
+ reader.start()
+ time.sleep(0.1)
+
+ for writer in writers:
+ writer.start()
+ time.sleep(0.1)
+
+ while numActive(readers) + numActive(writers) > 0:
+ time.sleep(1)
+
def run():
- # Set up the testing environment
+ print 'Setting up...'
+ sys.stdout.flush()
setUp()
+
+ print 'Stressing...'
+ sys.stdout.flush()
stress()
+
+ print 'Tearing down...'
+ sys.stdout.flush()
tearDown()
More information about the Zope-CVS
mailing list