Revision: 186
http://polepos.svn.sourceforge.net/polepos/?rev=186&view=rev
Author: carlrosenberger
Date: 2011-02-17 17:15:21 +0000 (Thu, 17 Feb 2011)
Log Message:
-----------
cr + pr: Work on concurrency circuit and fixed time circuit runner.
Modified Paths:
--------------
trunk/polepos/settings/Circuits.properties
trunk/polepos/settings/DebugCircuits.properties
trunk/polepos/src/org/polepos/Db4oVersionRace.java
trunk/polepos/src/org/polepos/RunSeason.java
trunk/polepos/src/org/polepos/circuits/arraylists/ArrayLists.java
trunk/polepos/src/org/polepos/circuits/commits/Commits.java
trunk/polepos/src/org/polepos/circuits/nativeids/NativeIds.java
trunk/polepos/src/org/polepos/circuits/strings/Strings.java
trunk/polepos/src/org/polepos/circuits/trees/Trees.java
trunk/polepos/src/org/polepos/framework/Circuit.java
trunk/polepos/src/org/polepos/framework/CircuitBase.java
trunk/polepos/src/org/polepos/framework/ConcurrencyCircuit.java
trunk/polepos/src/org/polepos/framework/ConcurrentDriver.java
trunk/polepos/src/org/polepos/framework/Driver.java
trunk/polepos/src/org/polepos/framework/DriverBase.java
trunk/polepos/src/org/polepos/framework/Racer.java
trunk/polepos/src/org/polepos/framework/ReflectiveCircuitBase.java
trunk/polepos/src/org/polepos/framework/Result.java
trunk/polepos/src/org/polepos/framework/TurnSetup.java
trunk/polepos/src/org/polepos/framework/TurnSetupConfig.java
trunk/polepos/src/org/polepos/reporters/PlainTextReporter.java
trunk/polepos/src/org/polepos/runner/AbstractRunner.java
trunk/polepos/src/org/polepos/teams/cobra/CobraCar.java
trunk/polepos/src/org/polepos/teams/cobra/CobraDriver.java
trunk/polepos/src/org/polepos/teams/db4o/ComplexDb4o.java
trunk/polepos/src/org/polepos/teams/db4o/Db4oDriver.java
trunk/polepos/src/org/polepos/teams/db4o/Db4oTeam.java
trunk/polepos/src/org/polepos/teams/hibernate/HibernateDriver.java
trunk/polepos/src/org/polepos/teams/hibernate/HibernateTeam.java
trunk/polepos/src/org/polepos/teams/hibernate/NativeIdsHibernate.java
trunk/polepos/src/org/polepos/teams/jdbc/CommitsJdbc.java
trunk/polepos/src/org/polepos/teams/jdbc/ComplexJdbc.java
trunk/polepos/src/org/polepos/teams/jdbc/FlatObjectJdbc.java
trunk/polepos/src/org/polepos/teams/jdbc/InheritanceHierarchyJdbc.java
trunk/polepos/src/org/polepos/teams/jdbc/JdbcCar.java
trunk/polepos/src/org/polepos/teams/jdbc/JdbcDriver.java
trunk/polepos/src/org/polepos/teams/jdbc/JdbcTeam.java
trunk/polepos/src/org/polepos/teams/jdbc/NativeIdsJdbc.java
trunk/polepos/src/org/polepos/teams/jdbc/NestedListsJdbc.java
trunk/polepos/src/org/polepos/teams/jdbc/TreesJdbc.java
trunk/polepos/src/org/polepos/teams/jdo/JdoCar.java
trunk/polepos/src/org/polepos/teams/jdo/JdoDriver.java
trunk/polepos/src/org/polepos/teams/jdo/JdoTeam.java
trunk/polepos/src/org/polepos/teams/jpa/JpaCar.java
trunk/polepos/src/org/polepos/teams/jpa/JpaDriver.java
trunk/polepos/src/org/polepos/teams/jvi/JviCar.java
trunk/polepos/src/org/polepos/teams/jvi/JviDriver.java
Added Paths:
-----------
trunk/polepos/src/org/polepos/circuits/complexconcurrency/
trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrency.java
trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrencyDriver.java
trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java
trunk/polepos/src/org/polepos/framework/FixedTimeDriver.java
trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java
trunk/polepos/src/org/polepos/framework/FixedTimeResult.java
trunk/polepos/src/org/polepos/framework/RacingStrategy.java
trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java
trunk/polepos/src/org/polepos/framework/TimedLapsRacingStrategy.java
trunk/polepos/src/org/polepos/framework/TimedLapsResult.java
trunk/polepos/src/org/polepos/teams/db4o/ComplexConcurrencyDb4o.java
trunk/polepos/src/org/polepos/teams/jdo/ComplexConcurrencyJdo.java
Removed Paths:
-------------
trunk/polepos/src/org/polepos/framework/CarMotorFailureException.java
Modified: trunk/polepos/settings/Circuits.properties
===================================================================
--- trunk/polepos/settings/Circuits.properties 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/settings/Circuits.properties 2011-02-17 17:15:21 UTC (rev 186)
@@ -105,3 +105,15 @@
nativeids.commitinterval=1000,1000,1000
+
+# complexconcurrency
+#
+# [threads]: number of worker threads
+# [time]: time until stopped
+
+complexconcurrency.threads=1,3,10
+complexconcurrency.time=1000,1000,1000
+complexconcurrency.objects=3,3,3
+complexconcurrency.depth=3,3,3
+complexconcurrency.selects=10,10,10
+
Modified: trunk/polepos/settings/DebugCircuits.properties
===================================================================
--- trunk/polepos/settings/DebugCircuits.properties 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/settings/DebugCircuits.properties 2011-02-17 17:15:21 UTC (rev 186)
@@ -103,3 +103,17 @@
nativeids.selects=500,500,500
nativeids.commitinterval=1000,1000,1000
+
+
+# complexconcurrency
+#
+# [threads]: number of worker threads
+# [time]: time until stopped
+
+complexconcurrency.threads=1,3,10
+complexconcurrency.time=1000,1000,1000
+complexconcurrency.objects=3,3,3
+complexconcurrency.depth=3,3,3
+complexconcurrency.selects=10,10,10
+
+
Modified: trunk/polepos/src/org/polepos/Db4oVersionRace.java
===================================================================
--- trunk/polepos/src/org/polepos/Db4oVersionRace.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/Db4oVersionRace.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -71,8 +71,8 @@
return teams;
}
- public CircuitBase[] circuits() {
- return new CircuitBase[] {
+ public Circuit[] circuits() {
+ return new Circuit[] {
new ReflectiveCircuitBase(Complex.class),
new ReflectiveCircuitBase(NestedLists.class),
new ReflectiveCircuitBase(InheritanceHierarchy.class),
Modified: trunk/polepos/src/org/polepos/RunSeason.java
===================================================================
--- trunk/polepos/src/org/polepos/RunSeason.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/RunSeason.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -24,6 +24,7 @@
import org.polepos.circuits.arraylists.*;
import org.polepos.circuits.commits.*;
import org.polepos.circuits.complex.*;
+import org.polepos.circuits.complexconcurrency.*;
import org.polepos.circuits.flatobject.*;
import org.polepos.circuits.inheritancehierarchy.*;
import org.polepos.circuits.nativeids.*;
@@ -57,8 +58,11 @@
}
@Override
- public CircuitBase[] circuits() {
- return new CircuitBase[] {
+ public Circuit[] circuits() {
+ return new Circuit[] {
+
+ // new ComplexConcurrency(),
+
new ReflectiveCircuitBase(Complex.class),
new ReflectiveCircuitBase(NestedLists.class),
new ReflectiveCircuitBase(InheritanceHierarchy.class),
Modified: trunk/polepos/src/org/polepos/circuits/arraylists/ArrayLists.java
===================================================================
--- trunk/polepos/src/org/polepos/circuits/arraylists/ArrayLists.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/circuits/arraylists/ArrayLists.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -5,7 +5,7 @@
import org.polepos.framework.*;
-public class ArrayLists extends CircuitBase{
+public class ArrayLists extends TimedLapsCircuitBase{
@Override
public String description() {
Modified: trunk/polepos/src/org/polepos/circuits/commits/Commits.java
===================================================================
--- trunk/polepos/src/org/polepos/circuits/commits/Commits.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/circuits/commits/Commits.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -22,7 +22,7 @@
import org.polepos.framework.*;
-public class Commits extends CircuitBase{
+public class Commits extends TimedLapsCircuitBase{
@Override
public String description() {
Added: trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrency.java
===================================================================
--- trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrency.java (rev 0)
+++ trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrency.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,38 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.circuits.complexconcurrency;
+
+
+import org.polepos.framework.*;
+
+public class ComplexConcurrency extends FixedTimeCircuitBase{
+
+ @Override
+ public String description() {
+ return "runs the complex scenario against multiple concurrent clients within a fixed time span";
+ }
+
+ @Override
+ public Class<?> requiredDriver() {
+ return ComplexConcurrencyDriver.class;
+ }
+
+}
Property changes on: trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrency.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrencyDriver.java
===================================================================
--- trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrencyDriver.java (rev 0)
+++ trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrencyDriver.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,27 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.circuits.complexconcurrency;
+
+import org.polepos.framework.*;
+
+public interface ComplexConcurrencyDriver extends FixedTimeDriver {
+
+}
Property changes on: trunk/polepos/src/org/polepos/circuits/complexconcurrency/ComplexConcurrencyDriver.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/polepos/src/org/polepos/circuits/nativeids/NativeIds.java
===================================================================
--- trunk/polepos/src/org/polepos/circuits/nativeids/NativeIds.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/circuits/nativeids/NativeIds.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -21,7 +21,7 @@
import org.polepos.framework.*;
-public class NativeIds extends CircuitBase {
+public class NativeIds extends TimedLapsCircuitBase {
@Override
public String description() {
Modified: trunk/polepos/src/org/polepos/circuits/strings/Strings.java
===================================================================
--- trunk/polepos/src/org/polepos/circuits/strings/Strings.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/circuits/strings/Strings.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -23,7 +23,7 @@
import org.polepos.framework.*;
-public class Strings extends CircuitBase{
+public class Strings extends TimedLapsCircuitBase{
@Override
public String description(){
Modified: trunk/polepos/src/org/polepos/circuits/trees/Trees.java
===================================================================
--- trunk/polepos/src/org/polepos/circuits/trees/Trees.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/circuits/trees/Trees.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -21,7 +21,7 @@
import org.polepos.framework.*;
-public class Trees extends CircuitBase
+public class Trees extends TimedLapsCircuitBase
{
@Override
Deleted: trunk/polepos/src/org/polepos/framework/CarMotorFailureException.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/CarMotorFailureException.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/CarMotorFailureException.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -1,27 +0,0 @@
-/*
-This file is part of the PolePosition database benchmark
-http://www.polepos.org
-
-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. */
-
-package org.polepos.framework;
-
-
-public class CarMotorFailureException extends Exception{
-
- private static final long serialVersionUID = 1L;
-
-}
Modified: trunk/polepos/src/org/polepos/framework/Circuit.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/Circuit.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/Circuit.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -23,10 +23,8 @@
public interface Circuit {
- public TurnResult[] race(Team team, Car car, Driver driver);
+ public List<Lap> laps();
- public List<Lap> laps();
-
public TurnSetup[] lapSetups();
public Class<?> requiredDriver();
@@ -35,20 +33,17 @@
public String internalName();
- public String fileNamePrefix();
-
public String name();
public void setTurnSetups(TurnSetup[] turnSetups);
- public TurnSetup[] getTurnSetups();
-
public Driver[] nominate(Team team);
public void reportTo(Circuit circuit);
public boolean isConcurrency();
- public void runLapsBefore(Lap lap, TurnSetup turnSetup, DriverBase driver, Car car);
+ public RacingStrategy racingStrategy();
+
}
\ No newline at end of file
Modified: trunk/polepos/src/org/polepos/framework/CircuitBase.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/CircuitBase.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/CircuitBase.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -1,346 +1,87 @@
-/*
-This file is part of the PolePosition database benchmark
-http://www.polepos.org
-
-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. */
-
-package org.polepos.framework;
-
-import java.util.*;
-
-import org.polepos.util.*;
-import org.polepos.watcher.*;
-
-/**
- * a set of timed test cases that work against the same data
- */
-public abstract class CircuitBase implements Circuit {
-
- public static final String NUM_RUNS_PROPERTY_ID = "POLEPOS_NUM_RUNS";
- public static final String MEMORY_USAGE_PROPERTY_ID = "POLEPOS_MEMORY_USAGE";
-
- private final int _numRuns = Integer.parseInt(System.getProperty(NUM_RUNS_PROPERTY_ID, "1"));
- private final MemoryUsage _memoryUsage = memoryUsage();
-
- private static MemoryUsage memoryUsage() {
- try {
- return (MemoryUsage)Class.forName(System.getProperty(MEMORY_USAGE_PROPERTY_ID, SimpleMemoryUsage.class.getName())).newInstance();
- }
- catch (Exception exc) {
- exc.printStackTrace();
- return new SimpleMemoryUsage();
- }
- }
-
- private List<Lap> _laps;
-
- private TurnSetup[] _turnSetups;
-
- // TODO: watcher can be installed, and should be sorted, i.e. memory watcher
- // should start before time watcher
- private TimeWatcher _timeWatcher;
-
- // TODO: The effect of MemoryWatcher is too strong on the running tests.
- // We should investigate if we can get less intrusive results with JMX
- // private MemoryWatcher _memoryWatcher;
-
- private FileSizeWatcher _fileSizeWatcher;
-
- private Circuit _reportTo = this;
-
- protected CircuitBase(){
- initWatchers();
- }
-
- @Override
- public void setTurnSetups(TurnSetup[] turnSetups){
- _turnSetups = turnSetups;
- }
-
- private void initWatchers() {
- _timeWatcher = new TimeWatcher();
- // _memoryWatcher = new MemoryWatcher();
- _fileSizeWatcher = new FileSizeWatcher();
- }
-
- /**
- * public official name for reporting
- */
- @Override
- public String name(){
- String name = internalName();
- return name.substring(0,1).toUpperCase() + name.substring(1);
- }
-
- /**
- * internal name for BenchmarkSettings.properties
- */
- @Override
- public String internalName(){
- String name = className();
- int pos = name.lastIndexOf(".");
- return name.substring(pos + 1).toLowerCase();
- }
-
- protected String className() {
- return circuitClass().getName();
- }
-
- protected Class<?> circuitClass() {
- return this.getClass();
- }
-
- /**
- * describes the intent of this circuit, what it wants to test
- */
- @Override
- public abstract String description();
-
- /**
- * @return the driver class needed to run on this Circuit
- */
- @Override
- public abstract Class<?> requiredDriver();
-
- /**
- * @return the methods that are intended to be run
- */
- protected abstract void addLaps();
-
- protected void add(Lap lap){
- _laps.add(lap);
- lap.circuit(this);
- }
-
- /**
- * setups are needed for reporting
- */
- @Override
- public TurnSetup[] lapSetups(){
- return _turnSetups;
- }
-
- @Override
- public List<Lap> laps() {
- if(_laps == null){
- _laps = new ArrayList<Lap>();
- addLaps();
- }
- return _laps;
- }
-
- /**
- * calling all the laps for all the lapSetups
- */
- @Override
- public TurnResult[] race( Team team, Car car, Driver driver){
- TurnResult[] results = new TurnResult[ _turnSetups.length ];
-
- int index = 0;
-
- for(TurnSetup setup : _turnSetups) {
- System.out.println("*** Turn " + index);
- results[index++] = runTurn(team, car, driver, index, setup);
- }
- return results;
- }
-
- private TurnResult runTurn(Team team, Car car, Driver driver, int index, TurnSetup setup) {
-
- Map<Lap, Set<LapReading>> lapReadings = new HashMap<Lap, Set<LapReading>>();
- for (Lap lap : laps()) {
-
- if(lap.reportResult()) {
- lapReadings.put(lap, new HashSet<LapReading>());
- }
- }
- boolean warmUp = _numRuns > 1;
- for (int runIdx = 0; runIdx < _numRuns; runIdx++) {
-
- prepareDriverToRunLaps(car, driver, setup);
-
- for(Lap lap : laps()) {
-
- if(driver.canRunLap(lap)){
-
- System.out.println("*** Lap " + lap.name());
-
- LapReading lapReading = runLap(team, driver, setup, lap);
- if(!warmUp && lap.reportResult()) {
- lapReadings.get(lap).add(lapReading);
- }
- }
- }
-
- driver.backToPit();
-
- tearDownTurn(team, driver);
- warmUp = false;
- }
-
- TurnResult turnResult = new TurnResult();
- for (Lap lap : laps()) {
- if(!lap.reportResult()) {
- continue;
- }
- if(! driver.canRunLap(lap)){
- continue;
- }
- long time = 0;
- long memory = 0;
- long fileSize = 0;
- long checkSum = 0;
- Set<LapReading> curReadings = lapReadings.get(lap);
- for (LapReading curReading : curReadings) {
- time += curReading.time;
- memory += curReading.memory;
- fileSize += curReading.fileSize;
- checkSum += curReading.checkSum;
- }
- Result lapResult = new Result(_reportTo , team, lap, setup, index, time, memory, fileSize, checkSum);
- turnResult.report(lapResult);
- }
- return turnResult;
- }
-
- private void prepareDriverToRunLaps(Car car, Driver driver, TurnSetup setup) {
- car.team().setUp();
-
- try {
- driver.takeSeatIn(car, setup);
- } catch (CarMotorFailureException e1) {
- throw new RuntimeException("Circuit aborted", e1);
- }
-
- try {
- driver.prepare();
- } catch (CarMotorFailureException e) {
- e.printStackTrace();
- }
- }
-
- private void tearDownTurn(Team team, Driver driver) {
- team.tearDown();
- driver.circuitCompleted();
- }
-
- private LapReading runLap(Team team, Driver driver, TurnSetup setup, Lap lap) {
-
- Runnable lapRunnable = driver.prepareLap(lap);
-
- if( ! lap.hot() ){
- driver.backToPit();
-
- try {
- driver.prepare();
- } catch (CarMotorFailureException e) {
- e.printStackTrace();
- }
- }
-
- MemoryUtil.gc();
-
- // _memoryWatcher.start();
-
- _timeWatcher.start();
- _fileSizeWatcher.monitorFile(team.databaseFile());
- _fileSizeWatcher.start();
-
- lapRunnable.run();
-
- _timeWatcher.stop();
-
- // _memoryWatcher.stop();
-
- _fileSizeWatcher.stop();
-
- return new LapReading(_timeWatcher.value(), _memoryUsage.usedMemory(), _fileSizeWatcher.value(), driver.checkSum());
- }
-
- private final static class LapReading {
- public final long time;
- public final long memory;
- public final long fileSize;
- public final long checkSum;
-
- public LapReading(long time, long memory, long fileSize, long checkSum) {
- this.time = time;
- this.memory = memory;
- this.fileSize = fileSize;
- this.checkSum = checkSum;
- }
-
- @Override
- public String toString() {
- return time + " ms";
- }
- }
-
- public static interface MemoryUsage {
- long usedMemory();
- }
-
- public static class SimpleMemoryUsage implements MemoryUsage {
- public long usedMemory() {
- return MemoryUtil.usedMemory();
- }
- }
-
- public static class NullMemoryUsage implements MemoryUsage {
- public long usedMemory() {
- return 0;
- }
- }
-
- @Override
- public String fileNamePrefix() {
- return internalName();
- }
-
- @Override
- public Driver[] nominate(Team team){
- return team.nominate(this);
- }
-
- public void reportTo(Circuit circuit){
- _reportTo = circuit;
- }
-
- public boolean isConcurrency(){
- return false;
- }
-
- @Override
- public TurnSetup[] getTurnSetups() {
- return _turnSetups;
- }
-
- @Override
- public void runLapsBefore(Lap lap, TurnSetup turnSetup, DriverBase driver, Car car) {
- prepareDriverToRunLaps(car, driver, turnSetup);
- for (Lap currentLap : laps()) {
- if(currentLap == lap){
- return;
- }
- if(driver.canRunLap(lap)){
- runLap(car.team(), driver, turnSetup, currentLap);
- }
-
- }
- }
-
-}
-
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+import java.util.*;
+
+public abstract class CircuitBase implements Circuit {
+
+ protected TurnSetup[] _turnSetups;
+
+ protected Circuit _reportTo = this;
+
+ @Override
+ public void setTurnSetups(TurnSetup[] turnSetups) {
+ _turnSetups = turnSetups;
+ }
+
+ /**
+ * public official name for reporting
+ */
+ @Override
+ public String name() {
+ String name = internalName();
+ return name.substring(0,1).toUpperCase() + name.substring(1);
+ }
+
+ /**
+ * internal name for BenchmarkSettings.properties
+ */
+ @Override
+ public String internalName() {
+ String name = className();
+ int pos = name.lastIndexOf(".");
+ return name.substring(pos + 1).toLowerCase();
+ }
+
+ protected String className() {
+ return circuitClass().getName();
+ }
+
+ protected Class<?> circuitClass() {
+ return this.getClass();
+ }
+
+ @Override
+ public abstract List<Lap> laps();
+
+ @Override
+ public Driver[] nominate(Team team) {
+ return team.nominate(this);
+ }
+
+ public void reportTo(Circuit circuit) {
+ _reportTo = circuit;
+ }
+
+ public TurnSetup[] turnSetups() {
+ return _turnSetups;
+ }
+ /**
+ * setups are needed for reporting
+ */
+ @Override
+ public TurnSetup[] lapSetups(){
+ return _turnSetups;
+ }
+
+
+}
Modified: trunk/polepos/src/org/polepos/framework/ConcurrencyCircuit.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/ConcurrencyCircuit.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/ConcurrencyCircuit.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -22,16 +22,14 @@
import java.util.*;
-public class ConcurrencyCircuit implements Circuit {
+public class ConcurrencyCircuit extends TimedLapsCircuitBase {
public static final String NAME_ADD_ON = "Concurrency";
- private final Circuit _delegate;
+ private final TimedLapsCircuitBase _delegate;
- private TurnSetup[] _turnSetups;
-
- public ConcurrencyCircuit(Circuit delegate){
- _delegate = delegate;
+ public ConcurrencyCircuit(Circuit delegate){
+ _delegate = (TimedLapsCircuitBase) delegate;
}
@Override
@@ -59,10 +57,9 @@
return NAME_ADD_ON + " " + _delegate.name();
}
- @Override
public TurnResult[] race(Team team, Car car, Driver driver) {
- TurnSetup[] turnSetups = _delegate.getTurnSetups();
+ TurnSetup[] turnSetups = _delegate.turnSetups();
_delegate.setTurnSetups(_turnSetups);
_delegate.reportTo(this);
@@ -85,11 +82,6 @@
public void setTurnSetups(TurnSetup[] turnSetups) {
_turnSetups = turnSetups;
}
-
- @Override
- public String fileNamePrefix() {
- return _delegate.fileNamePrefix() + "_" + NAME_ADD_ON;
- }
@Override
public Driver[] nominate(Team team){
@@ -111,14 +103,22 @@
return true;
}
- @Override
- public TurnSetup[] getTurnSetups() {
+ public TurnSetup[] turnSetups() {
return _turnSetups;
}
- @Override
public void runLapsBefore(Lap lap, TurnSetup turnSetup, DriverBase driver, Car car) {
_delegate.runLapsBefore(lap, turnSetup, driver, car);
}
+
+ @Override
+ public RacingStrategy racingStrategy() {
+ return new TimedLapsRacingStrategy(this);
+ }
+ @Override
+ protected void addLaps() {
+ _delegate.addLaps();
+ }
+
}
Modified: trunk/polepos/src/org/polepos/framework/ConcurrentDriver.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/ConcurrentDriver.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/ConcurrentDriver.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -32,12 +32,11 @@
}
@Override
- public void takeSeatIn(Car car, TurnSetup setup)
- throws CarMotorFailureException {
+ public void configure(Car car, TurnSetup setup) {
int threadCount = setup.getThreadCount();
cloneMasterDriver(threadCount);
for(Driver driver : _drivers){
- driver.takeSeatIn(car, setup);
+ driver.configure(car, setup);
}
}
@@ -51,17 +50,17 @@
}
@Override
- public void backToPit() {
+ public void closeDatabase() {
// We send the master driver back to pit last,
// since it may have opened the server.
for (int i = 1; i < _drivers.length; i++) {
- _drivers[i].backToPit();
+ _drivers[i].closeDatabase();
}
- _drivers[0].backToPit();
+ _drivers[0].closeDatabase();
}
@Override
- public void prepare() throws CarMotorFailureException {
+ public void prepare() {
for(Driver driver : _drivers){
driver.prepare();
}
@@ -86,7 +85,8 @@
public Runnable prepareLap(final Lap lap) {
- lap.circuit().runLapsBefore(lap, lap.circuit().getTurnSetups()[0], _masterDriver, _masterDriver.car());
+ TimedLapsCircuitBase circuit = (TimedLapsCircuitBase) lap.circuit();
+ circuit.runLapsBefore(lap, circuit.turnSetups()[0], _masterDriver, _masterDriver.car());
for (int i = 1; i < _drivers.length; i++) {
_drivers[i].copyStateFrom(_masterDriver);
Modified: trunk/polepos/src/org/polepos/framework/Driver.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/Driver.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/Driver.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -20,7 +20,7 @@
package org.polepos.framework;
-public abstract class Driver {
+public abstract class Driver implements Cloneable{
public Driver() {
super();
@@ -30,12 +30,11 @@
public abstract long checkSum();
- public abstract void backToPit();
+ public abstract void closeDatabase();
- public abstract void prepare() throws CarMotorFailureException;
+ public abstract void prepare() ;
- public abstract void takeSeatIn(Car car, TurnSetup setup)
- throws CarMotorFailureException;
+ public abstract void configure(Car car, TurnSetup setup);
public abstract Runnable prepareLap(final Lap lap);
Modified: trunk/polepos/src/org/polepos/framework/DriverBase.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/DriverBase.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/DriverBase.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -51,7 +51,7 @@
* take a seat in a car.
*/
@Override
- public void takeSeatIn( Car car, TurnSetup setup ) throws CarMotorFailureException{
+ public void configure( Car car, TurnSetup setup ) {
mCar = car;
mSetup = setup;
_checkSum = 0;
@@ -62,7 +62,7 @@
* Normally opens the database.
*/
@Override
- public abstract void prepare() throws CarMotorFailureException;
+ public abstract void prepare();
/**
@@ -70,7 +70,7 @@
* created and close any resources it opened.
*/
@Override
- public abstract void backToPit();
+ public abstract void closeDatabase();
protected TurnSetup setup(){
Added: trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,47 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+import java.util.*;
+
+public abstract class FixedTimeCircuitBase extends CircuitBase {
+
+ @Override
+ public boolean isConcurrency() {
+ return false;
+ }
+
+ @Override
+ public RacingStrategy racingStrategy() {
+ return new FixedTimeRacingStrategy(this);
+ }
+
+ @Override
+ public List<Lap> laps() {
+ ArrayList<Lap> list = new ArrayList<Lap>();
+ Lap lap = new Lap("");
+ lap.circuit(this);
+ list.add(lap);
+ return list;
+ }
+
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/polepos/src/org/polepos/framework/FixedTimeDriver.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/FixedTimeDriver.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/FixedTimeDriver.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,29 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+public interface FixedTimeDriver {
+
+ public void bulkId(int id);
+
+ public void race();
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/FixedTimeDriver.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,152 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+import java.util.*;
+
+import org.polepos.reporters.*;
+import org.polepos.util.*;
+
+public class FixedTimeRacingStrategy implements RacingStrategy {
+
+
+ private final FixedTimeCircuitBase _circuit;
+
+ public FixedTimeRacingStrategy(FixedTimeCircuitBase circuit) {
+ _circuit = (FixedTimeCircuitBase) circuit;
+ }
+
+ @Override
+ public void race(Team team, Car car, Driver driver, List<Reporter> reporters) {
+ TurnSetup[] turnSetups = _circuit.turnSetups();
+ TurnResult[] results = new TurnResult[ turnSetups.length];
+ for (int i = 0; i < turnSetups.length; i++) {
+ Result result = raceTurn(team, car, driver, turnSetups[i], i);
+ TurnResult turnResult = new TurnResult();
+ turnResult.report(result);
+ results[i] = turnResult;
+ }
+ for (Reporter reporter : reporters) {
+ reporter.report(team, car, turnSetups, results);
+ }
+
+ }
+
+ private Result raceTurn(Team team, Car car, Driver driver, TurnSetup setup, int setupIndex) {
+ car.team().setUp();
+
+ driver.configure(car, setup);
+ driver.prepare();
+ // fill database
+
+ driver.closeDatabase();
+
+ MemoryUtil.gc();
+
+ int threadCount = setup.getThreadCount();
+
+ int time = setup.getTime();
+
+ DriverBase[] drivers = new DriverBase[threadCount];
+ ConcurrentTurnRacer[] racers = new ConcurrentTurnRacer[threadCount];
+ Thread[] threads = new Thread[threadCount];
+
+ for (int i = 0; i < threads.length; i++) {
+ drivers[i] = ((DriverBase)driver).clone();
+ // drivers[i].configure(car, setup);
+ drivers[i].prepare();
+ drivers[i].bulkId(i + 1);
+ racers[i] = new ConcurrentTurnRacer((FixedTimeDriver)drivers[i]);
+ threads[i] = new Thread(racers[i]);
+ }
+
+ for (int i = 0; i < threads.length; i++) {
+ threads[i].start();
+ }
+
+ try {
+ Thread.sleep(time);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ for (int i = 0; i < threads.length; i++) {
+ racers[i].stop();
+ }
+
+ for (int i = 0; i < threads.length; i++) {
+ try {
+ threads[i].join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ long iterations = 0;
+
+ for (int i = 0; i < threads.length; i++) {
+ drivers[i].closeDatabase();
+ iterations += racers[i].iterations();
+ }
+
+
+ // FIXME: Change to FixedTimeResult
+ // Result result = new FixedTimeResult(_circuit, _circuit.laps().get(0), team,turnSetups[i],i,iterations);
+
+ Result result = new TimedLapsResult(_circuit, team,_circuit.laps().get(0), setup ,setupIndex,iterations,0,0,0);
+
+ team.tearDown();
+ driver.circuitCompleted();
+ return result;
+ }
+
+ private static class ConcurrentTurnRacer implements Runnable {
+
+ private long _iterations;
+
+ private volatile boolean _stopped;
+
+ private FixedTimeDriver _driver;
+
+ ConcurrentTurnRacer(FixedTimeDriver driver){
+ _driver = driver;
+ }
+
+ @Override
+ public void run() {
+ while(! _stopped){
+ _driver.race();
+ _iterations++;
+ }
+
+ }
+
+ public void stop(){
+ _stopped = true;
+ }
+
+ public long iterations(){
+ return _iterations;
+ }
+ }
+
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/polepos/src/org/polepos/framework/FixedTimeResult.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/FixedTimeResult.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/FixedTimeResult.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,61 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+public class FixedTimeResult extends Result {
+
+ private final long _iterations;
+
+ public FixedTimeResult(Circuit circuit, Lap lap, Team team, TurnSetup setup, int index, long iterations) {
+ super(circuit, lap, team, setup, index);
+ _iterations = iterations;
+ }
+
+ public long iterations(){
+ return _iterations;
+ }
+
+ @Override
+ public String getName() {
+ return getCircuit().name();
+ }
+
+ @Override
+ public long getCheckSum() {
+ return 0;
+ }
+
+ @Override
+ public long getDatabaseSize() {
+ return 0;
+ }
+
+ @Override
+ public long getMemory() {
+ return 0;
+ }
+
+ @Override
+ public long getTime() {
+ return 0;
+ }
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/FixedTimeResult.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/polepos/src/org/polepos/framework/Racer.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/Racer.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/Racer.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -73,24 +73,11 @@
for (Reporter reporter : reporters) {
reporter.sendToCircuit(circuit);
}
-
for (Driver driver : drivers) {
-
System.out.println("** On track: " + team.name() + "/" + car.name());
- long startTime = System.currentTimeMillis();
-
-
- TurnSetup[] setups = circuit.lapSetups();
- TurnResult[] results = circuit.race(team, car, driver);
-
- long stopTime = System.currentTimeMillis();
- long t = stopTime - startTime;
- System.out.println("Time[ms]: " + t);
-
- for (Reporter reporter : reporters) {
- reporter.report(team, car, setups, results);
- }
+ RacingStrategy racingStrategy = circuit.racingStrategy();
+ racingStrategy.race(team, car, driver, reporters);
}
}
Added: trunk/polepos/src/org/polepos/framework/RacingStrategy.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/RacingStrategy.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/RacingStrategy.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,31 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+import java.util.*;
+
+import org.polepos.reporters.*;
+
+public interface RacingStrategy {
+
+ void race(Team team, Car car, Driver driver, List<Reporter> reporters);
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/RacingStrategy.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/polepos/src/org/polepos/framework/ReflectiveCircuitBase.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/ReflectiveCircuitBase.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/ReflectiveCircuitBase.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -24,7 +24,7 @@
import java.util.*;
-public class ReflectiveCircuitBase extends CircuitBase {
+public class ReflectiveCircuitBase extends TimedLapsCircuitBase {
private final Class<?> _driverClass;
Modified: trunk/polepos/src/org/polepos/framework/Result.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/Result.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/Result.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -22,9 +22,8 @@
/**
* a result for a lap that holds the name and the time.
*/
-public class Result {
+public abstract class Result {
-
private final Circuit _circuit;
private final Team _team;
@@ -35,34 +34,19 @@
private final Lap _lap;
- private final long _time;
-
- private final long _checkSum;
-
- private final long _memory;
-
- private final long _databaseSize;
-
- public Result(Circuit circuit, Team team, Lap lap, TurnSetup setup, int index, long time, long memory, long databaseSize, long checkSum){
+ public Result(Circuit circuit, Lap lap, Team team, TurnSetup setup, int index){
_circuit = circuit;
_team = team;
- _lap = lap;
_setup = setup;
+ _lap = lap;
_index = index;
- _time = time;
- _memory = memory;
- _databaseSize = databaseSize;
- _checkSum = checkSum;
+
}
- public String getName(){
- return _lap.name();
- }
+ public String getName() {
+ return _lap.name();
+ }
- public long getTime(){
- return _time;
- }
-
public TurnSetup getSetup(){
return _setup;
}
@@ -75,24 +59,23 @@
return _circuit;
}
- public Lap getLap(){
- return _lap;
- }
-
- public long getCheckSum(){
- return _checkSum;
- }
-
public Team getTeam(){
- return _team;
+ return _team;
}
- public long getMemory(){
- return _memory;
+ public Lap getLap(){
+ return _lap;
}
- public long getDatabaseSize() {
- return _databaseSize;
- }
+ public abstract long getCheckSum();
+
+ public abstract long getTime();
+
+ public abstract long getMemory();
+
+ public abstract long getDatabaseSize();
+
+
+
}
Copied: trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java (from rev 172, trunk/polepos/src/org/polepos/framework/CircuitBase.java)
===================================================================
--- trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,272 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+package org.polepos.framework;
+
+import java.util.*;
+
+import org.polepos.util.*;
+import org.polepos.watcher.*;
+
+/**
+ * a set of timed test cases that work against the same data
+ */
+public abstract class TimedLapsCircuitBase extends CircuitBase implements Circuit {
+
+ public static final String NUM_RUNS_PROPERTY_ID = "POLEPOS_NUM_RUNS";
+ public static final String MEMORY_USAGE_PROPERTY_ID = "POLEPOS_MEMORY_USAGE";
+
+ private final int _numRuns = Integer.parseInt(System.getProperty(NUM_RUNS_PROPERTY_ID, "1"));
+ private final MemoryUsage _memoryUsage = memoryUsage();
+
+ private static MemoryUsage memoryUsage() {
+ try {
+ return (MemoryUsage)Class.forName(System.getProperty(MEMORY_USAGE_PROPERTY_ID, SimpleMemoryUsage.class.getName())).newInstance();
+ }
+ catch (Exception exc) {
+ exc.printStackTrace();
+ return new SimpleMemoryUsage();
+ }
+ }
+
+ List<Lap> _laps;
+
+ // TODO: watcher can be installed, and should be sorted, i.e. memory watcher
+ // should start before time watcher
+ private TimeWatcher _timeWatcher;
+
+ // TODO: The effect of MemoryWatcher is too strong on the running tests.
+ // We should investigate if we can get less intrusive results with JMX
+ // private MemoryWatcher _memoryWatcher;
+
+ private FileSizeWatcher _fileSizeWatcher;
+
+ protected TimedLapsCircuitBase(){
+ initWatchers();
+ }
+
+ private void initWatchers() {
+ _timeWatcher = new TimeWatcher();
+ // _memoryWatcher = new MemoryWatcher();
+ _fileSizeWatcher = new FileSizeWatcher();
+ }
+
+ /**
+ * describes the intent of this circuit, what it wants to test
+ */
+ @Override
+ public abstract String description();
+
+ /**
+ * @return the driver class needed to run on this Circuit
+ */
+ @Override
+ public abstract Class<?> requiredDriver();
+
+ /**
+ * @return the methods that are intended to be run
+ */
+ protected abstract void addLaps();
+
+ protected void add(Lap lap){
+ _laps.add(lap);
+ lap.circuit(this);
+ }
+
+ /**
+ * calling all the laps for all the lapSetups
+ */
+ public TurnResult[] race( Team team, Car car, Driver driver){
+ TurnResult[] results = new TurnResult[ _turnSetups.length ];
+
+ int index = 0;
+
+ for(TurnSetup setup : _turnSetups) {
+ System.out.println("*** Turn " + index);
+ results[index++] = runTurn(team, car, driver, index, setup);
+ }
+ return results;
+ }
+
+ private TurnResult runTurn(Team team, Car car, Driver driver, int index, TurnSetup setup) {
+
+ Map<Lap, Set<LapReading>> lapReadings = new HashMap<Lap, Set<LapReading>>();
+ for (Lap lap : laps()) {
+
+ if(lap.reportResult()) {
+ lapReadings.put(lap, new HashSet<LapReading>());
+ }
+ }
+ boolean warmUp = _numRuns > 1;
+ for (int runIdx = 0; runIdx < _numRuns; runIdx++) {
+
+ prepareDriverToRunLaps(car, driver, setup);
+
+ for(Lap lap : laps()) {
+
+ if(driver.canRunLap(lap)){
+
+ System.out.println("*** Lap " + lap.name());
+
+ LapReading lapReading = runLap(team, driver, setup, lap);
+ if(!warmUp && lap.reportResult()) {
+ lapReadings.get(lap).add(lapReading);
+ }
+ }
+ }
+
+ driver.closeDatabase();
+
+ tearDownTurn(team, driver);
+ warmUp = false;
+ }
+
+ TurnResult turnResult = new TurnResult();
+ for (Lap lap : laps()) {
+ if(!lap.reportResult()) {
+ continue;
+ }
+ if(! driver.canRunLap(lap)){
+ continue;
+ }
+ long time = 0;
+ long memory = 0;
+ long fileSize = 0;
+ long checkSum = 0;
+ Set<LapReading> curReadings = lapReadings.get(lap);
+ for (LapReading curReading : curReadings) {
+ time += curReading.time;
+ memory += curReading.memory;
+ fileSize += curReading.fileSize;
+ checkSum += curReading.checkSum;
+ }
+ Result lapResult = new TimedLapsResult(_reportTo , team, lap, setup, index, time, memory, fileSize, checkSum);
+ turnResult.report(lapResult);
+ }
+ return turnResult;
+ }
+
+ private void prepareDriverToRunLaps(Car car, Driver driver, TurnSetup setup) {
+ car.team().setUp();
+ driver.configure(car, setup);
+ driver.prepare();
+ }
+
+ private void tearDownTurn(Team team, Driver driver) {
+ team.tearDown();
+ driver.circuitCompleted();
+ }
+
+ private LapReading runLap(Team team, Driver driver, TurnSetup setup, Lap lap) {
+
+ Runnable lapRunnable = driver.prepareLap(lap);
+
+ if( ! lap.hot() ){
+ driver.closeDatabase();
+ driver.prepare();
+ }
+
+ MemoryUtil.gc();
+
+ // _memoryWatcher.start();
+
+ _timeWatcher.start();
+ _fileSizeWatcher.monitorFile(team.databaseFile());
+ _fileSizeWatcher.start();
+
+ lapRunnable.run();
+
+ _timeWatcher.stop();
+
+ // _memoryWatcher.stop();
+
+ _fileSizeWatcher.stop();
+
+ return new LapReading(_timeWatcher.value(), _memoryUsage.usedMemory(), _fileSizeWatcher.value(), driver.checkSum());
+ }
+
+ private final static class LapReading {
+ public final long time;
+ public final long memory;
+ public final long fileSize;
+ public final long checkSum;
+
+ public LapReading(long time, long memory, long fileSize, long checkSum) {
+ this.time = time;
+ this.memory = memory;
+ this.fileSize = fileSize;
+ this.checkSum = checkSum;
+ }
+
+ @Override
+ public String toString() {
+ return time + " ms";
+ }
+ }
+
+ public static interface MemoryUsage {
+ long usedMemory();
+ }
+
+ public static class SimpleMemoryUsage implements MemoryUsage {
+ public long usedMemory() {
+ return MemoryUtil.usedMemory();
+ }
+ }
+
+ public static class NullMemoryUsage implements MemoryUsage {
+ public long usedMemory() {
+ return 0;
+ }
+ }
+
+ public boolean isConcurrency(){
+ return false;
+ }
+
+ public void runLapsBefore(Lap lap, TurnSetup turnSetup, DriverBase driver, Car car) {
+ prepareDriverToRunLaps(car, driver, turnSetup);
+ for (Lap currentLap : laps()) {
+ if(currentLap == lap){
+ return;
+ }
+ if(driver.canRunLap(lap)){
+ runLap(car.team(), driver, turnSetup, currentLap);
+ }
+
+ }
+ }
+
+ @Override
+ public RacingStrategy racingStrategy() {
+ return new TimedLapsRacingStrategy(this);
+ }
+
+ @Override
+ public List<Lap> laps() {
+ if(_laps == null){
+ _laps = new ArrayList<Lap>();
+ addLaps();
+ }
+ return _laps;
+ }
+
+
+}
+
Added: trunk/polepos/src/org/polepos/framework/TimedLapsRacingStrategy.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/TimedLapsRacingStrategy.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/TimedLapsRacingStrategy.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,53 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+import java.util.*;
+
+import org.polepos.reporters.*;
+
+public class TimedLapsRacingStrategy implements RacingStrategy {
+
+ private final TimedLapsCircuitBase _circuit;
+
+ public TimedLapsRacingStrategy(TimedLapsCircuitBase circuit) {
+ _circuit = circuit;
+ }
+
+ @Override
+ public void race(Team team, Car car, Driver driver, List<Reporter> reporters) {
+
+ long startTime = System.currentTimeMillis();
+
+ TurnSetup[] setups = _circuit.lapSetups();
+ TurnResult[] results = _circuit.race(team, car, driver);
+
+ long stopTime = System.currentTimeMillis();
+ long t = stopTime - startTime;
+ System.out.println("Time[ms]: " + t);
+
+ for (Reporter reporter : reporters) {
+ reporter.report(team, car, setups, results);
+ }
+
+ }
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/TimedLapsRacingStrategy.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/polepos/src/org/polepos/framework/TimedLapsResult.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/TimedLapsResult.java (rev 0)
+++ trunk/polepos/src/org/polepos/framework/TimedLapsResult.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -0,0 +1,61 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+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. */
+
+
+package org.polepos.framework;
+
+public class TimedLapsResult extends Result{
+
+ private final long _time;
+
+ private final long _checkSum;
+
+ private final long _memory;
+
+ private final long _databaseSize;
+
+ public TimedLapsResult(Circuit circuit, Team team, Lap lap,
+ TurnSetup setup, int index, long time, long memory,
+ long databaseSize, long checkSum) {
+ super(circuit, lap, team, setup, index);
+
+ _time = time;
+ _checkSum = checkSum;
+ _memory = memory;
+ _databaseSize = databaseSize;
+ }
+
+ public long getTime(){
+ return _time;
+ }
+
+ public long getCheckSum(){
+ return _checkSum;
+ }
+
+ public long getMemory(){
+ return _memory;
+ }
+
+ public long getDatabaseSize() {
+ return _databaseSize;
+ }
+
+
+}
Property changes on: trunk/polepos/src/org/polepos/framework/TimedLapsResult.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/polepos/src/org/polepos/framework/TurnSetup.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/TurnSetup.java 2011-02-14 20:21:43 UTC (rev 185)
+++ trunk/polepos/src/org/polepos/framework/TurnSetup.java 2011-02-17 17:15:21 UTC (rev 186)
@@ -167,6 +167,10 @@
public int getThreadCount() {
return getSetting(TurnSetupConfig.THREADCOUNT);
}
+
+ public int getTime() {
+ return getSetting(TurnSetupConfig.TIME);
+ }
...
[truncated message content] |