diff --git a/src/main/java/org/polypheny/simpleclient/main/ChronosAgent.java b/src/main/java/org/polypheny/simpleclient/main/ChronosAgent.java index 707593a..e9ace38 100644 --- a/src/main/java/org/polypheny/simpleclient/main/ChronosAgent.java +++ b/src/main/java/org/polypheny/simpleclient/main/ChronosAgent.java @@ -178,6 +178,10 @@ protected Object prepare( ChronosJob chronosJob, final File inputDirectory, fina // Parse CDL Map parsedConfig = parseConfig( chronosJob ); + if ( !parsedConfig.containsKey( "queryMode" ) ) { + throw new RuntimeException( "Query mode not specified" ); + } + switch ( parsedConfig.get( "queryMode" ) ) { case "Table": queryMode = QueryMode.TABLE; diff --git a/src/main/java/org/polypheny/simpleclient/main/ProgressReporter.java b/src/main/java/org/polypheny/simpleclient/main/ProgressReporter.java index fa7c373..d03ab77 100644 --- a/src/main/java/org/polypheny/simpleclient/main/ProgressReporter.java +++ b/src/main/java/org/polypheny/simpleclient/main/ProgressReporter.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.List; +import java.util.Queue; import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; import org.polypheny.simpleclient.query.QueryListEntry; @@ -70,12 +71,12 @@ public static class ReportQueryListProgress implements Runnable { private final int totalNumber; private final ProgressReporter theProgressReporter; - private final List theList; + private final Queue theQueue; - public ReportQueryListProgress( List list, ProgressReporter progressReporter ) { + public ReportQueryListProgress( Queue list, ProgressReporter progressReporter ) { this.totalNumber = list.size(); - this.theList = list; + this.theQueue = list; this.theProgressReporter = progressReporter; } @@ -83,8 +84,8 @@ public ReportQueryListProgress( List list, ProgressReporter prog @Override public void run() { while ( true ) { - theProgressReporter.update( totalNumber - theList.size(), totalNumber ); - if ( theList.isEmpty() ) { + theProgressReporter.update( totalNumber - theQueue.size(), totalNumber ); + if ( theQueue.isEmpty() ) { break; } try { @@ -97,7 +98,7 @@ public void run() { public void updateProgress() { - theProgressReporter.update( totalNumber - theList.size(), totalNumber ); + theProgressReporter.update( totalNumber - theQueue.size(), totalNumber ); } } diff --git a/src/main/java/org/polypheny/simpleclient/scenario/EvaluationThread.java b/src/main/java/org/polypheny/simpleclient/scenario/EvaluationThread.java index 678dc0e..94a7ea2 100644 --- a/src/main/java/org/polypheny/simpleclient/scenario/EvaluationThread.java +++ b/src/main/java/org/polypheny/simpleclient/scenario/EvaluationThread.java @@ -29,6 +29,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import lombok.Getter; @@ -43,7 +44,7 @@ public class EvaluationThread extends Thread { private final Executor executor; - private final List queries; + private final Queue queries; private boolean abort = false; @Setter private EvaluationThreadMonitor threadMonitor; @@ -55,7 +56,7 @@ public class EvaluationThread extends Thread { final boolean commitAfterEveryQuery; - public EvaluationThread( List queryList, Executor executor, Set templateIds, boolean commitAfterEveryQuery ) { + public EvaluationThread( Queue queryList, Executor executor, Set templateIds, boolean commitAfterEveryQuery ) { super( "EvaluationThread" ); this.executor = executor; this.queries = queryList; @@ -72,11 +73,8 @@ public void run() { while ( !queries.isEmpty() && !abort ) { measuredTimeStart = System.nanoTime(); - try { - queryListEntry = queries.removeFirst(); - } catch ( IndexOutOfBoundsException e ) { // This is neither nice nor efficient... - // This can happen due to concurrency if two threads enter the while-loop and there is only one thread left - // Simply leaf the loop + queryListEntry = queries.poll(); + if ( queryListEntry == null ) { break; } try { diff --git a/src/main/java/org/polypheny/simpleclient/scenario/PolyphenyScenario.java b/src/main/java/org/polypheny/simpleclient/scenario/PolyphenyScenario.java index 21c39df..5b200e3 100644 --- a/src/main/java/org/polypheny/simpleclient/scenario/PolyphenyScenario.java +++ b/src/main/java/org/polypheny/simpleclient/scenario/PolyphenyScenario.java @@ -34,8 +34,10 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Queue; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Function; import java.util.function.Supplier; import lombok.extern.slf4j.Slf4j; @@ -61,11 +63,13 @@ public PolyphenyScenario( JdbcExecutor.ExecutorFactory executorFactory, boolean } - protected long commonExecute( List queryList, ProgressReporter progressReporter, File outputDirectory, int numberOfThreads, Function toString, Supplier executor, Random random ) { - Collections.shuffle( queryList, random ); + protected long commonExecute( List queries, ProgressReporter progressReporter, File outputDirectory, int numberOfThreads, Function toString, Supplier executor, Random random ) { + Collections.shuffle( queries, random ); // This dumps the queries independent of the selected interface - dumpQueryList( outputDirectory, queryList, toString ); + dumpQueryList( outputDirectory, queries, toString ); + + Queue queryList = new ConcurrentLinkedQueue<>( queries ); log.info( "Executing benchmark..." ); (new Thread( new ProgressReporter.ReportQueryListProgress( queryList, progressReporter ) )).start(); diff --git a/src/main/java/org/polypheny/simpleclient/scenario/Scenario.java b/src/main/java/org/polypheny/simpleclient/scenario/Scenario.java index 9ceb928..e7614f8 100644 --- a/src/main/java/org/polypheny/simpleclient/scenario/Scenario.java +++ b/src/main/java/org/polypheny/simpleclient/scenario/Scenario.java @@ -26,8 +26,6 @@ import com.google.common.base.Joiner; import java.io.File; -import java.text.DecimalFormat; -import java.text.ParseException; import java.util.List; import java.util.LongSummaryStatistics; import java.util.Map; @@ -101,17 +99,9 @@ protected void calculateResults( Map queryTypes, Properties pro protected double calculateMean( List times ) { - DecimalFormat df = new DecimalFormat( "0.000" ); OptionalDouble meanOptional = times.stream().mapToLong( Long::longValue ).average(); if ( meanOptional.isPresent() ) { - // scale - double mean = meanOptional.getAsDouble() / 1000000.0; - String roundFormat = df.format( mean ); - try { - return df.parse( roundFormat ).doubleValue(); - } catch ( ParseException e ) { - log.error( "Exception", e ); - } + return Math.round( meanOptional.getAsDouble() / 1_000 ) / 1_000.0; } return -1; } @@ -125,15 +115,7 @@ protected double calculateSampleStandardDeviation( List times, double mean protected double processDoubleValue( double value ) { - DecimalFormat df = new DecimalFormat( "0.000" ); - double temp1 = value / 1_000_000; - String roundFormat = df.format( temp1 ); - try { - return df.parse( roundFormat ).doubleValue(); - } catch ( ParseException e ) { - log.error( "Exception", e ); - } - return -1; + return Math.round( value / 1_000 ) / 1_000.0; } diff --git a/src/main/java/org/polypheny/simpleclient/scenario/coms/Coms.java b/src/main/java/org/polypheny/simpleclient/scenario/coms/Coms.java index b315cd8..b4e0d12 100644 --- a/src/main/java/org/polypheny/simpleclient/scenario/coms/Coms.java +++ b/src/main/java/org/polypheny/simpleclient/scenario/coms/Coms.java @@ -35,6 +35,7 @@ import java.util.List; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Function; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; @@ -276,7 +277,7 @@ private void startEvaluation( ProgressReporter progressReporter, CsvWriter csvWr ArrayList threads = new ArrayList<>(); for ( List queryList : organized ) { - threads.add( new EvaluationThread( queryList, executorFactory.createExecutorInstance( csvWriter, NAMESPACE ), queryTypes.keySet(), commitAfterEveryQuery ) ); + threads.add( new EvaluationThread( new ConcurrentLinkedQueue<>( queryList ), executorFactory.createExecutorInstance( csvWriter, NAMESPACE ), queryTypes.keySet(), commitAfterEveryQuery ) ); } EvaluationThreadMonitor threadMonitor = new EvaluationThreadMonitor( threads );