[Erp5-report] r13649 - /erp5/trunk/utils/oood/testOoodHighLoad.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Mar 26 15:22:04 CEST 2007


Author: bartek
Date: Mon Mar 26 15:22:02 2007
New Revision: 13649

URL: http://svn.erp5.org?rev=13649&view=rev
Log:
added test for high randomly distributed load

Added:
    erp5/trunk/utils/oood/testOoodHighLoad.py

Added: erp5/trunk/utils/oood/testOoodHighLoad.py
URL: http://svn.erp5.org/erp5/trunk/utils/oood/testOoodHighLoad.py?rev=13649&view=auto
==============================================================================
--- erp5/trunk/utils/oood/testOoodHighLoad.py (added)
+++ erp5/trunk/utils/oood/testOoodHighLoad.py Mon Mar 26 15:22:02 2007
@@ -1,0 +1,144 @@
+#!/usr/bin/python
+##############################################################################
+#
+# Copyright (c) 2002, 2006 Nexedi SARL and Contributors. All Rights Reserved.
+#                    Jean-Paul Smets-Solanes <jp at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+
+"""
+  This test sends random numbers of random ODF files to oood, to convert them to random formats,
+  all at random intervals. This is to simulate production environment.
+  First it creates a list of all ODF docs which are in the system to pick up files from it.
+"""
+
+import base64
+import itertools
+import os
+import pdb
+import random
+import sys
+import thread
+import threading
+import time
+import unittest
+from xmlrpclib import *
+
+sys.path.append('/etc/oood')
+import config
+
+enc = base64.encodestring
+dec = base64.decodestring
+
+sp = ServerProxy('http://%s:%d' % (config.server_host, config.server_port), allow_none = True)
+
+# create a list of od? files if not present
+all_odfs_name = config.oood_home + '/all_odf_docs'
+all_odfs_creation_command = 'find / | egrep "\.od[stp]{1}$" > %s' % all_odfs_name
+if not os.path.exists(all_odfs_name):
+  print "creating a list of ODF documents in the system - this can take a while, but I do it only once..."
+  os.system(all_odfs_creation_command)
+file_names = open(all_odfs_name).readlines()
+
+def log(msg):
+  """
+    a helper function to print and log the same thing
+  """
+  stamp = time.strftime('%d, %H:%M:%S')
+  thread_name = threading.currentThread().getName()
+  msg = '%s : %s : %s' % (stamp, thread_name, msg)
+  print(msg)
+
+ext2mime = {
+    'odt':'application/vnd.oasis.opendocument.text',
+    'ods':'application/vnd.oasis.opendocument.spreadsheet',
+    'odp':'application/vnd.oasis.opendocument.presentation'
+  }
+
+lock = threading.Lock()
+
+class TestScalability(unittest.TestCase):
+
+  def generateFormat(self):
+    """
+      take a random file from od? file list, randomly choose one target format
+      from among allowed targets, generate, check if it returned
+    """
+    try:
+      # acquire a lock to make sure another thread does not change target_list in the meantime
+      lock.acquire()
+      # make sure the file is there
+      while True:
+        fname = '/home/bartek/' + random.choice(file_names).strip()
+        if os.path.exists(fname):
+          break
+      target_list = sp.getAllowedTargets(ext2mime[fname[-3:]])
+      tgt = random.choice(target_list)[:]
+      lock.release()
+      log('%s --> %s' % (fname,tgt[1]))
+      data = open(fname).read()
+      res = sp.run_generate(fname, enc(data), None, tgt[0])
+      res = bool(res)
+      self.failUnless(res)
+    except Exception, e:
+      print e
+      try:
+        lock.release()
+      except: # we ignore "release unlocked lock" exception
+        pass
+      raise
+
+  def testRandomLoad(self):
+    """
+      random number of generation requests (1-5)fired up at the same time
+      by separate threads
+      sleep random number of seconds (1-30)
+      do it 100 times
+    """
+    counter = 0
+    repeat = 100
+    print ' '
+    for iteration in range(repeat):
+      random.seed()
+      batch_size = random.randint(1, 5)
+      interval = random.randint(1, 30)
+      log('batch %d, interval %d' % (batch_size, interval))
+      for i in range(batch_size):
+        counter += 1
+        t = threading.Thread(target=self.generateFormat)
+        t.start()
+      time.sleep(interval)
+
+if __name__=='__main__':
+  tests=(TestScalability,)
+  for t in tests:
+    suite=unittest.makeSuite(t)
+    unittest.TextTestRunner(verbosity=2).run(suite)
+
+
+
+
+
+
+# vim: filetype=python syntax=python shiftwidth=2 




More information about the Erp5-report mailing list