[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7230 - in trunk/gnue-appserver/samples/testing: . benchmark
From: |
johannes |
Subject: |
[gnue] r7230 - in trunk/gnue-appserver/samples/testing: . benchmark |
Date: |
Sun, 20 Mar 2005 04:14:05 -0600 (CST) |
Author: johannes
Date: 2005-03-20 04:14:04 -0600 (Sun, 20 Mar 2005)
New Revision: 7230
Added:
trunk/gnue-appserver/samples/testing/benchmark/
trunk/gnue-appserver/samples/testing/benchmark/benchmark.gcd
trunk/gnue-appserver/samples/testing/benchmark/modify.py
trunk/gnue-appserver/samples/testing/benchmark/query.py
Log:
Added benchmark tests for appserver
Property changes on: trunk/gnue-appserver/samples/testing/benchmark
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.log
Added: trunk/gnue-appserver/samples/testing/benchmark/benchmark.gcd
===================================================================
--- trunk/gnue-appserver/samples/testing/benchmark/benchmark.gcd
2005-03-19 23:10:47 UTC (rev 7229)
+++ trunk/gnue-appserver/samples/testing/benchmark/benchmark.gcd
2005-03-20 10:14:04 UTC (rev 7230)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<module name="benchmark">
+
+ <class name="simple">
+ <property name="value" type="string(20)" />
+ </class>
+
+ <class name="name">
+ <property name="code" type="string(8)" nullable="False" />
+ <property name="name" type="string(35)" />
+ <property name="mark" type="number(4)" />
+
+ <property name="alwaystrue" type="boolean">
+ return True
+ </property>
+
+ <property name="fullname" type="string(50)">
+ return "%s-%s" % (self.code.strip (), self.name.strip ())
+ </property>
+
+ <index name="ixname" unique="False">
+ <indexfield name="name" />
+ </index>
+ </class>
+
+</module>
+
Added: trunk/gnue-appserver/samples/testing/benchmark/modify.py
===================================================================
--- trunk/gnue-appserver/samples/testing/benchmark/modify.py 2005-03-19
23:10:47 UTC (rev 7229)
+++ trunk/gnue-appserver/samples/testing/benchmark/modify.py 2005-03-20
10:14:04 UTC (rev 7230)
@@ -0,0 +1,259 @@
+# GNU Enterprise Application Server - Benchmark unit - Data modifications
+#
+# Copyright 2003-2004 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise 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, or (at your option) any later version.
+#
+# GNU Enterprise 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 program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id: $
+
+import sys
+import time
+import os
+
+from gnue.appserver.language import App
+
+
+# =============================================================================
+# Application class for benchmarks
+# =============================================================================
+
+class benchmarkApp (App.App):
+ """
+ This class derives from the base language interface application and adds
+ another command line option (logfile).
+ """
+
+ def __init__ (self, connections = None, application = 'appserver',
+ defaults = None):
+
+ self.addCommandOption ('logfile', 'l', argument='file',
default='bench.log',
+ help = _("Logfile to dump statistics"))
+
+ App.App.__init__ (self, connections, application, defaults)
+
+
+
+# -----------------------------------------------------------------------------
+# Insert a new record into benchmark_simple
+# -----------------------------------------------------------------------------
+
+def _insertFunction (session, item):
+ """
+ Insert a new record into benchmark_simple
+ @param session: the session to use
+ @param item: value to set for the new record
+ @return: created instance
+ """
+
+ element = session.new ('simple')
+ element.value = item
+
+ return element
+
+
+# -----------------------------------------------------------------------------
+# Update a given record
+# -----------------------------------------------------------------------------
+
+def _updateFunction (session, item):
+ """
+ Update a record in benchmark_simple by doubling it's value
+ @param session: session to use
+ @param item: the record instance to be modified
+ @return: the modified instance
+ """
+
+ v = item.value
+ item.value = v * 2
+
+ return item
+
+
+# -----------------------------------------------------------------------------
+# Delete a given record in benchmark_simple
+# -----------------------------------------------------------------------------
+
+def _deleteFunction (session, item):
+ """
+ Delete the given record
+ @param session: session to use
+ @param item: the record instance to delete
+ """
+
+ item.delete ()
+ return None
+
+
+# -----------------------------------------------------------------------------
+# Process a given set of records
+# -----------------------------------------------------------------------------
+
+def processRecords (session, records, singleCommit, processFunction, note,
+ logfile):
+ """
+ Process a given set of records using a processor function.
+ @param session: session to be passed to the processor function
+ @param records: call the processor function for all elements of this iterable
+ object
+ @param singleCommit: if True, a commit will be called after every item of
+ records, otherwise a commit will be called after the last element of
+ records has been processed.
+ @param processFunction: this function will be called per item of records
+ @param note: print this text before starting the iteration
+ @param logfile: file to dump stats in
+
+ @return: sequence of return-values of the processFunction (one per
+ records-element)
+ """
+
+ result = []
+
+ print "=" * 50
+ print "\n"
+ print note
+ print "Number of records:", len (records)
+ print "Running a commit :",
+
+ if singleCommit:
+ print "after every iteration"
+ else:
+ print "after the last iteration"
+
+ print
+
+ start = time.time ()
+
+ snaps = []
+ numRecs = len (records)
+ marks = numRecs / 4
+ last = start
+ index = 0
+
+ commitTime = 0 # Overall time of all commits
+
+ for item in records:
+ index += 1
+
+ # If we hit a mark, store the time consumed for processing up to here
+ if not index % marks:
+ now = time.time ()
+ print " reached mark", index, "of", numRecs
+
+ snaps.append ((now - last))
+ last = now
+
+ # Process record
+ result.append (processFunction (session, item))
+
+ if singleCommit:
+ commitStart = time.time ()
+ session.commit ()
+ commitTime += time.time () - commitStart
+
+ # If not in singleCommit mode, perform the commit here
+ if not singleCommit:
+ commitStart = time.time ()
+ session.commit ()
+ commitTime = time.time () - commitStart
+
+ overall = time.time () - start
+
+ dumpStats (overall, commitTime, snaps, singleCommit, numRecs, note, logfile)
+
+ return result
+
+
+# -----------------------------------------------------------------------------
+# Print execution statistics
+# -----------------------------------------------------------------------------
+
+def dumpStats (overall, commit, snaps, singleCommit, nRecs, descr, logfile):
+ """
+ Print execution statistics given by the arguments.
+ @param overall: overall time used for a given process
+ @param commit: time spent for all commits during the process
+ @param snaps: time spent per mark during the process
+ @param singleCommit: if True, a commit was done per iteration
+ @param nRecs: number of records processed
+ @param descr: description of the process
+ @param logfile: filename to dump stats to
+ """
+
+ print "-" * 50
+ print "Overall time : %14.8f" % overall
+ print "Iteration time: %14.8f" % (overall - commit)
+ print "Commit time : %14.8f" % commit
+
+ print "Snaps:"
+ for ix in range (len (snaps)):
+ print " up to mark %d: %14.8f" % ((ix+1), snaps [ix])
+
+ f = open (logfile, 'a')
+ try:
+ f.write ('Opertation: %s%s' % (descr, os.linesep))
+ f.write ('# Records : %d%s' % (nRecs, os.linesep))
+
+ if singleCommit:
+ f.write ('Commit : after every iteration%s' % (os.linesep * 2))
+ else:
+ f.write ('Commit : after the last iteration%s' % (os.linesep * 2))
+
+ f.write ('Overall time : %14.8f%s' % (overall, os.linesep))
+ f.write ('Iteration time: %14.8f%s' % ((overall - commit), os.linesep))
+ f.write ('Commit time : %14.8f%s' % (commit, (os.linesep * 2)))
+ f.write ('Snaps:%s' % os.linesep)
+ for ix in range (len (snaps)):
+ f.write (' up to mark %d: %14.8f%s' % ((ix+1), snaps [ix], os.linesep))
+ f.write ('%s%s' % (('-' * 70), os.linesep))
+
+ finally:
+ f.close ()
+
+ print "\n<Return> to continue"
+ raw_input ()
+
+
+# =============================================================================
+# Main program
+# =============================================================================
+
+if __name__ == "__main__":
+ app = benchmarkApp ()
+
+ logfile = app.OPTIONS ['logfile']
+ session = app.newSession ('test', 'test')
+
+ try:
+ session.setcontext ('benchmark')
+
+ theRange = xrange (200)
+
+ a = processRecords (session, theRange, False, _insertFunction,
+ "Insert new records", logfile)
+ b = processRecords (session, theRange, True, _insertFunction,
+ "Insert new records", logfile)
+
+ processRecords (session, a, False, _updateFunction, "Update", logfile)
+ processRecords (session, b, True, _updateFunction, "Update", logfile)
+
+ processRecords (session, a, False, _deleteFunction, "Delete", logfile)
+ processRecords (session, b, True, _deleteFunction, "Delete", logfile)
+
+
+ finally:
+ session.close ()
Property changes on: trunk/gnue-appserver/samples/testing/benchmark/modify.py
___________________________________________________________________
Name: svn:keyword
+ Id
Added: trunk/gnue-appserver/samples/testing/benchmark/query.py
===================================================================
--- trunk/gnue-appserver/samples/testing/benchmark/query.py 2005-03-19
23:10:47 UTC (rev 7229)
+++ trunk/gnue-appserver/samples/testing/benchmark/query.py 2005-03-20
10:14:04 UTC (rev 7230)
@@ -0,0 +1,222 @@
+# GNU Enterprise Application Server - Benchmark unit - Data modifications
+#
+# Copyright 2003-2004 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise 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, or (at your option) any later version.
+#
+# GNU Enterprise 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 program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id: $
+
+import time
+import os
+
+from gnue.appserver.language import App
+
+
+# =============================================================================
+# Application class for benchmarks
+# =============================================================================
+
+class benchmarkApp (App.App):
+ """
+ This class derives from the base language interface application and adds
+ another command line option (logfile).
+ """
+
+ def __init__ (self, connections = None, application = 'appserver',
+ defaults = None):
+
+ self.addCommandOption ('logfile', 'l', argument='file',
default='bench.log',
+ help = _("Logfile to dump statistics"))
+
+ App.App.__init__ (self, connections, application, defaults)
+
+
+
+# -----------------------------------------------------------------------------
+# Clear all records from a given table
+# -----------------------------------------------------------------------------
+
+def clearTable (session, table):
+ """
+ This function deletes all records from a given table and calls a commit
+ """
+
+ print "Removing data from", table, "..."
+
+ for i in session.find (table):
+ i.delete ()
+
+ session.commit ()
+ print "Done"
+
+
+# -----------------------------------------------------------------------------
+# Populate some sample information into benchmark_name
+# -----------------------------------------------------------------------------
+
+def populateNames (session, aRange, words):
+ """
+ """
+
+ clearTable (session, 'benchmark_name')
+
+ print "Populating names ..."
+ marks = len (aRange) / 4
+ wordseq = words.keys () [:len (aRange)]
+ if len (wordseq) < len (aRange):
+ diff = len (aRange) - len (wordseq)
+ for i in range (diff):
+ wordseq.append ('Foo%d' % i)
+
+ for item in aRange:
+ index = item + 1
+ if index % marks == 0:
+ print " reached mark", index, "of", len (aRange)
+
+ name = session.new ('name')
+ name.code = hex (index)
+ name.name = wordseq [item] [:35]
+ name.mark = int (index / marks)
+ session.commit ()
+
+ print "Done."
+
+def buildNamesDict ():
+ """
+ """
+
+ result = {}
+
+ f = open (__file__, 'r')
+ try:
+ lines = f.readlines ()
+
+ for line in lines:
+ for word in line.split ():
+ result [word] = True
+ result [word.lower ()] = True
+ result [word.upper ()] = True
+ result [word.title ()] = True
+
+ finally:
+ f.close ()
+
+ return result
+
+
+def logwrite (log, message):
+ """
+ """
+
+ print message
+ log.write ('%s%s' % (message, os.linesep))
+
+
+# -----------------------------------------------------------------------------
+# Run a find and iterate over it's result
+# -----------------------------------------------------------------------------
+
+def runFind (session, cond = None, order = [u'gnue_id'], props = ['name'],
+ rollback = True, logfile = None):
+ """
+ """
+
+ # Merge order and properties, but don't duplicate names
+ pd = {}.fromkeys ((order or []) + props)
+ props = pd.keys ()
+
+ logwrite (logfile, "-" * 75)
+ logwrite (logfile, "Running a find () on 'benchmark_name'")
+ logwrite (logfile, "Rollback : %s" % \
+ (rollback and 'performed' or '*no* rollback'))
+ logwrite (logfile, "Condition : %s" % cond)
+ logwrite (logfile, "Order-By : %s" % order)
+ logwrite (logfile, "Properties: %s" % props)
+ logwrite (logfile, "")
+
+ if rollback:
+ session.rollback ()
+
+ start = time.time ()
+ result = session.find ('name', cond, order, props)
+ ftime = time.time () - start
+
+ for i in result:
+ x = i.name
+
+ overall = time.time () - start
+
+ logwrite (logfile, "# Records: %d" % len (result))
+ logwrite (logfile, "Find : %14.8f" % ftime)
+ logwrite (logfile, "Iteration: %14.8f" % (overall - ftime))
+ logwrite (logfile, "Overall : %14.8f" % overall)
+ logwrite (logfile, "")
+
+ print "<Return> to continue"
+ raw_input ()
+
+
+# =============================================================================
+# Main program
+# =============================================================================
+
+if __name__ == "__main__":
+ app = benchmarkApp ()
+ session = app.newSession ('test', 'test')
+
+ words = buildNamesDict ()
+
+ log = open (app.OPTIONS ['logfile'], 'a')
+ try:
+ try:
+ session.setcontext ('benchmark')
+
+ theRange = xrange (20)
+
+ populateNames (session, theRange, words)
+
+ # return all, no condition, no special order
+ runFind (session, logfile = log)
+
+ # return only records from the first mark
+ cond = ['eq', ['field', 'mark'], ['const', 0]]
+ runFind (session, cond = cond, logfile = log)
+
+ # return all records, with a dummy condition on a calculated field (which
+ # evaluates to True for all records)
+ runFind (session, {'alwaystrue': True}, logfile = log)
+
+ runFind (session, order = ['name'], logfile = log)
+
+ runFind (session, order = ['code'], logfile = log)
+
+ runFind (session, order = ['fullname', 'name'], logfile = log)
+ runFind (session, order = ['name', 'fullname'], logfile = log)
+
+ cond = ['like', ['field', 'fullname'], ['const', '0x1%']]
+ runFind (session, cond, ['fullname', 'name'], logfile = log)
+
+ cond = ['like', ['field', 'code'], ['const', '0x1%']]
+ runFind (session, cond, ['fullname', 'name'], logfile = log)
+
+
+ finally:
+ session.close ()
+
+ finally:
+ log.close ()
Property changes on: trunk/gnue-appserver/samples/testing/benchmark/query.py
___________________________________________________________________
Name: svn:keyword
+ Id
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7230 - in trunk/gnue-appserver/samples/testing: . benchmark,
johannes <=