Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ buildscript {
url = uri("https://plugins.gradle.org/m2/")
}
}

dependencies {
// Shadowing; used to make a fat jar (https://github.com/johnrengelman/shadow)
classpath group: "com.github.johnrengelman", name: "shadow", version: "8.1.1"
Expand Down Expand Up @@ -192,6 +193,7 @@ shadowJar {
mergeServiceFiles {
setPath("META-INF/services")
include("io.grpc.*")
include("java.sql.Driver")
}
// Include everything from 'libs' but rename JARs to another extension to trick the plugin
from('libs') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019-3/21/25, 1:02 PM The Polypheny Project
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.polypheny.simpleclient.cli;

import com.github.rvesse.airline.annotations.Arguments;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
import java.sql.SQLException;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.simpleclient.executor.Executor.ExecutorFactory;
import org.polypheny.simpleclient.executor.PolyphenyDbJdbcExecutor.PolyphenyDbJdbcExecutorFactory;
import org.polypheny.simpleclient.main.LockingBenchScenario;

@Slf4j
@Command(name = "locking", description = "Mode for quick testing of Polypheny-DB using the locking benchmark.")
public class LockingBenchCommand implements CliRunnable {

@Arguments(description = "Task { schema | data | workload | warmup }.")
private List<String> args;

@Option(name = { "-pdb", "--polyphenydb" }, title = "IP or Hostname", arity = 1, description = "IP or Hostname of Polypheny-DB (default: 127.0.0.1).")
public static String polyphenyDbHost = "127.0.0.1";

@Option(name = { "-s", "--sessions" }, title = "Numbers of sessions", arity = 1, description = "The number of session accessing the database simultaneously (default 5).")
public int sessionCount = 5;

@Option(name = { "-n", "--namespaces" }, title = "Numbers of namespaces", arity = 1, description = "The number of namespaces the entities are distributed over (default 2).")
public int namespaceCount = 2;

@Option(name = { "-e", "--entities" }, title = "Numbers of entities", arity = 1, description = "The number of entities to be used created in each namespace (default 5).")
public int entityCount = 5;

@Option(name = { "-r", "--rwRatio" }, title = "Read Write Ratio", arity = 1, description = "The ratio between read and modify/write queries from 0 to 1 (default 0.5).")
public double readWriteRatio = 0.5;


@Override
public int run() throws SQLException {
if ( args == null || args.isEmpty() ) {
System.err.println( "Missing task" );
System.exit( 1 );
}

ExecutorFactory executorFactory = new PolyphenyDbJdbcExecutorFactory( polyphenyDbHost, false );

try {
if ( args.getFirst().equalsIgnoreCase( "schema" ) ) {
LockingBenchScenario.schema( executorFactory, sessionCount, namespaceCount, entityCount, readWriteRatio );
} else if ( args.getFirst().equalsIgnoreCase( "data" ) ) {
LockingBenchScenario.data( executorFactory, sessionCount, namespaceCount, entityCount, readWriteRatio );
} else if ( args.getFirst().equalsIgnoreCase( "workload" ) ) {
LockingBenchScenario.workload( executorFactory, sessionCount, namespaceCount, entityCount, readWriteRatio );
} else if ( args.getFirst().equalsIgnoreCase( "warmup" ) ) {
LockingBenchScenario.warmup( executorFactory, sessionCount, namespaceCount, entityCount, readWriteRatio );
} else {
System.err.println( "Unknown task: " + args.get( 0 ) );
}
} catch ( Throwable t ) {
log.error( "Exception while executing LockingBench!", t );
System.exit( 1 );
}

return 0;
}


}
1 change: 1 addition & 0 deletions src/main/java/org/polypheny/simpleclient/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void main( String[] args ) throws SQLException {
builder.withCommands( YcsbCommand.class );
builder.withCommands( DumpCommand.class );
builder.withCommands( HelpCommand.class );
builder.withCommands( LockingBenchCommand.class );
builder.withDefaultCommand( HelpCommand.class );

Cli<CliRunnable> cli = builder.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019-3/21/25, 1:19 PM The Polypheny Project
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.polypheny.simpleclient.main;

import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.simpleclient.executor.Executor.ExecutorFactory;
import org.polypheny.simpleclient.scenario.lockingBench.LockingBench;
import org.polypheny.simpleclient.scenario.lockingBench.LockingBenchConfig;

@Slf4j
public class LockingBenchScenario {

public static void schema( ExecutorFactory executorFactory, int sessionCount, int namespaceCount, int entityCount, double readWriteRatio ) {
LockingBenchConfig config = new LockingBenchConfig( getProperties(sessionCount), sessionCount, namespaceCount, entityCount, readWriteRatio );
LockingBench lockingBench = new LockingBench( executorFactory, config );
lockingBench.createSchema( null, false );
}


public static void data( ExecutorFactory executorFactory, int sessionCount, int namespaceCount, int entityCount, double readWriteRatio ) {
LockingBenchConfig config = new LockingBenchConfig( getProperties(sessionCount), sessionCount, namespaceCount, entityCount, readWriteRatio );
LockingBench lockingBench = new LockingBench( executorFactory, config );
ProgressReporter progressReporter = new ProgressBar( config.sessionCount, config.progressReportBase );
lockingBench.generateData( null, progressReporter );
}


public static void warmup( ExecutorFactory executorFactory, int sessionCount, int namespaceCount, int entityCount, double readWriteRatio ) {
LockingBenchConfig config = new LockingBenchConfig( getProperties(sessionCount), sessionCount, namespaceCount, entityCount, readWriteRatio );
LockingBench lockingBench = new LockingBench( executorFactory, config );
ProgressReporter progressReporter = new ProgressBar( config.sessionCount, config.progressReportBase );
lockingBench.warmUp( progressReporter );
}


public static void workload( ExecutorFactory executorFactory, int sessionCount, int namespaceCount, int entityCount, double readWriteRatio ) {
LockingBenchConfig config = new LockingBenchConfig( getProperties(sessionCount), sessionCount, namespaceCount, entityCount, readWriteRatio );
LockingBench lockingBench = new LockingBench( executorFactory, config );
ProgressReporter progressReporter = new ProgressBar( config.sessionCount, config.progressReportBase );
final CsvWriter writer = new CsvWriter( "results.csv" );
lockingBench.execute( progressReporter, writer, new File("."), config.sessionCount );
}


private static Properties getProperties(int sessionCount) {
Properties props = new Properties();
try {
props.load( Objects.requireNonNull( ClassLoader.getSystemResourceAsStream( "org/polypheny/simpleclient/scenario/lockingBench/lockingbench.properties" ) ) );
props.put("numberOfThreads", String.valueOf( sessionCount ) );
} catch ( IOException e ) {
log.error( "Exception while reading properties file", e );
}
return props;
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/polypheny/simpleclient/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Query( boolean expectResultSet ) {
}


public enum DataTypes {INTEGER, VARCHAR, TIMESTAMP, DATE, ARRAY_INT, ARRAY_REAL, BYTE_ARRAY, FILE}
public enum DataTypes {SMALLINT, TEXT, DECIMAL, INTEGER, BIGINT, TINYINT, BOOLEAN, VARCHAR, TIMESTAMP, DATE, ARRAY_INT, ARRAY_REAL, BYTE_ARRAY, FILE}


public abstract String getSql();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@
@Slf4j
public class EvaluationThread extends Thread {

private final Executor executor;
private final Queue<QueryListEntry> queries;
private boolean abort = false;
protected final Executor executor;
protected final Queue<QueryListEntry> queries;
protected boolean abort = false;
@Setter
private EvaluationThreadMonitor threadMonitor;
protected EvaluationThreadMonitor threadMonitor;

private final List<Long> measuredTimes = Collections.synchronizedList( new LinkedList<>() );
protected final List<Long> measuredTimes = Collections.synchronizedList( new LinkedList<>() );

private final Map<Integer, List<Long>> measuredTimePerQueryType = new ConcurrentHashMap<>();
protected final Map<Integer, List<Long>> measuredTimePerQueryType = new ConcurrentHashMap<>();

final boolean commitAfterEveryQuery;
protected final boolean commitAfterEveryQuery;


public EvaluationThread( Queue<QueryListEntry> queryList, Executor executor, Set<Integer> templateIds, boolean commitAfterEveryQuery ) {
Expand All @@ -67,66 +67,63 @@ public EvaluationThread( Queue<QueryListEntry> queryList, Executor executor, Set

@Override
public void run() {
long measuredTimeStart;
long measuredTime;
QueryListEntry queryListEntry;

while ( !queries.isEmpty() && !abort ) {
measuredTimeStart = System.nanoTime();
queryListEntry = queries.poll();
QueryListEntry queryListEntry = queries.poll();
if ( queryListEntry == null ) {
break;
}
try {
executor.executeQuery( queryListEntry.query );
} catch ( ExecutorException e ) {
log.error( "Caught exception while executing queries", e );
threadMonitor.notifyAboutError( e );
try {
executor.executeRollback();
} catch ( ExecutorException ex ) {
log.error( "Error while rollback", e );
}
throw new RuntimeException( e );
}
measuredTime = System.nanoTime() - measuredTimeStart;
measuredTimes.add( measuredTime );
measuredTimePerQueryType.get( queryListEntry.templateId ).add( measuredTime );
for ( Integer id : queryListEntry.templateIds ) {
if ( id != queryListEntry.templateId ) {
measuredTimePerQueryType.get( id ).add( measuredTime );
}
}

executeAndMeasure( queryListEntry );

if ( commitAfterEveryQuery ) {
try {
executor.executeCommit();
} catch ( ExecutorException e ) {
log.error( "Caught exception while committing", e );
threadMonitor.notifyAboutError( e );
try {
executor.executeRollback();
} catch ( ExecutorException ex ) {
log.error( "Error while rollback", e );
}
throw new RuntimeException( e );
}
commitSafely();
}
}

commitSafely();
executor.flushCsvWriter();
}


protected void executeAndMeasure( QueryListEntry queryListEntry ) {
long startTime = System.nanoTime();
try {
executor.executeQuery( queryListEntry.query );
} catch ( ExecutorException e ) {
log.error( "Caught exception while executing queries", e );
threadMonitor.notifyAboutError( e );
rollbackSafely( e );
throw new RuntimeException( e );
}
long measuredTime = System.nanoTime() - startTime;
measuredTimes.add( measuredTime );
measuredTimePerQueryType.get( queryListEntry.templateId ).add( measuredTime );
for ( Integer id : queryListEntry.templateIds ) {
if ( !id.equals( queryListEntry.templateId ) ) {
measuredTimePerQueryType.get( id ).add( measuredTime );
}
}
}


protected void commitSafely() {
try {
executor.executeCommit();
} catch ( ExecutorException e ) {
log.error( "Caught exception while committing", e );
threadMonitor.notifyAboutError( e );
try {
executor.executeRollback();
} catch ( ExecutorException ex ) {
log.error( "Error while rollback", e );
}
rollbackSafely( e );
throw new RuntimeException( e );
}
}

executor.flushCsvWriter();

protected void rollbackSafely( Exception originalException ) {
try {
executor.executeRollback();
} catch ( ExecutorException rollbackException ) {
log.error( "Error while rollback", originalException );
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
import java.util.List;
import lombok.Getter;

public final class EvaluationThreadMonitor {
public class EvaluationThreadMonitor {

private final List<EvaluationThread> threads;
private final List<? extends EvaluationThread> threads;
@Getter
private Exception exception;
@Getter
private boolean aborted;


public EvaluationThreadMonitor( List<EvaluationThread> threads ) {
public EvaluationThreadMonitor( List<? extends EvaluationThread> threads ) {
this.threads = threads;
this.aborted = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void analyze( Properties properties, File outputDirectory ) {
}


private void dumpQueryList( File outputDirectory, List<QueryListEntry> queryList, Function<Query, String> toString ) {
protected void dumpQueryList( File outputDirectory, List<QueryListEntry> queryList, Function<Query, String> toString ) {
if ( outputDirectory != null && dumpQueryList ) {
log.info( "Dump query list..." );
try {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/polypheny/simpleclient/scenario/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ protected void calculateResults( Map<Integer, String> queryTypes, Properties pro
long min = summaryStatistics.getMin();
double stddev = calculateSampleStandardDeviation( time, mean );

properties.put( "queryTypes_" + templateId + "_mean", processDoubleValue( mean ) );
properties.put( "queryTypes_" + templateId + "_mean [ms]", processDoubleValue( mean ) );
if ( ChronosAgent.STORE_INDIVIDUAL_QUERY_TIMES ) {
properties.put( "queryTypes_" + templateId + "_all", Joiner.on( ',' ).join( time ) );
properties.put( "queryTypes_" + templateId + "_all [ms]", Joiner.on( ',' ).join( time ) );
}
properties.put( "queryTypes_" + templateId + "_stddev", processDoubleValue( stddev ) );
properties.put( "queryTypes_" + templateId + "_min", min / 1_000_000L );
properties.put( "queryTypes_" + templateId + "_max", max / 1_000_000L );
properties.put( "queryTypes_" + templateId + "_stddev [ms]", processDoubleValue( stddev ) );
properties.put( "queryTypes_" + templateId + "_min [ms]", min / 1_000_000L );
properties.put( "queryTypes_" + templateId + "_max [ms]", max / 1_000_000L );
} else {
properties.put( "queryTypes_" + templateId + "_mean", 0 );
properties.put( "queryTypes_" + templateId + "_stddev", 0 );
properties.put( "queryTypes_" + templateId + "_min", 0 );
properties.put( "queryTypes_" + templateId + "_max", 0 );
properties.put( "queryTypes_" + templateId + "_mean [ms]", 0 );
properties.put( "queryTypes_" + templateId + "_stddev [ms]", 0 );
properties.put( "queryTypes_" + templateId + "_min [ms]", 0 );
properties.put( "queryTypes_" + templateId + "_max [ms]", 0 );
}
properties.put( "queryTypes_" + templateId + "_example", queryTypes.get( templateId ) );
}
Expand Down
Loading