Skip to content

Commit

Permalink
Merge branch 'knn-metadata-queries'
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Dec 8, 2020
2 parents d1653c9 + dedddf6 commit 72120f0
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ protected double calculateMean( List<Long> times ) {


protected double calculateSampleStandardDeviation( List<Long> times, double mean ) {
double preVariance = times.stream().mapToDouble( it -> Math.pow( ( it - mean ), 2 ) ).sum();
double variance = preVariance / ( times.size() - 1.0 );
double preVariance = times.stream().mapToDouble( it -> Math.pow( (it - mean), 2 ) ).sum();
double variance = preVariance / (times.size() - 1.0);
return Math.sqrt( variance );
}


protected double processDoubleValue( double value ) {
DecimalFormat df = new DecimalFormat( "0.000" );
double temp1 = value / 1_000_000;
String roundFormat = df.format( value );
String roundFormat = df.format( temp1 );
try {
return df.parse( roundFormat ).doubleValue();
} catch ( ParseException e ) {
Expand All @@ -102,6 +102,7 @@ protected double processDoubleValue( double value ) {
return -1;
}


public abstract int getNumberOfInsertThreads();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.Map;
import java.util.OptionalDouble;
import java.util.Properties;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -32,10 +31,10 @@
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.CreateRealFeature;
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.MetadataKnnIntFeature;
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.MetadataKnnRealFeature;
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.SimpleKnnIdIntFeature;
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.SimpleKnnIdRealFeature;
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.SimpleKnnIntFeature;
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.SimpleKnnRealFeature;
import org.polypheny.simpleclient.scenario.knnbench.queryBuilder.SimpleMetadata;


@Slf4j
Expand Down Expand Up @@ -101,7 +100,8 @@ public long execute( ProgressReporter progressReporter, CsvWriter csvWriter, Fil
List<QueryListEntry> queryList = new Vector<>();
addNumberOfTimes( queryList, new SimpleKnnIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm ), config.numberOfSimpleKnnIntFeatureQueries );
addNumberOfTimes( queryList, new SimpleKnnRealFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm ), config.numberOfSimpleKnnRealFeatureQueries );
addNumberOfTimes( queryList, new SimpleKnnIdIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm ), config.numberOfSimpleKnnIdIntFeatureQueries );
addNumberOfTimes( queryList, new SimpleMetadata( config.randomSeedQuery, config.numberOfEntries ), config.numberOfSimpleMetadataQueries );
// addNumberOfTimes( queryList, new SimpleKnnIdIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm ), config.numberOfSimpleKnnIdIntFeatureQueries );
addNumberOfTimes( queryList, new SimpleKnnIdRealFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm ), config.numberOfSimpleKnnIdRealFeatureQueries );
addNumberOfTimes( queryList, new MetadataKnnIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm ), config.numberOfMetadataKnnIntFeatureQueries );
addNumberOfTimes( queryList, new MetadataKnnRealFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm ), config.numberOfMetadataKnnRealFeatureQueries );
Expand Down Expand Up @@ -172,7 +172,8 @@ public void warmUp( ProgressReporter progressReporter, int iterations ) {
Executor executor = null;
SimpleKnnIntFeature simpleKnnIntFeatureBuilder = new SimpleKnnIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm );
SimpleKnnRealFeature simpleKnnRealFeatureBuilder = new SimpleKnnRealFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm );
SimpleKnnIdIntFeature simpleKnnIdIntFeatureBuilder = new SimpleKnnIdIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm );
SimpleMetadata simpleMetadataBuilder = new SimpleMetadata( config.randomSeedQuery, config.numberOfEntries );
// SimpleKnnIdIntFeature simpleKnnIdIntFeatureBuilder = new SimpleKnnIdIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm );
SimpleKnnIdRealFeature simpleKnnIdRealFeatureBuilder = new SimpleKnnIdRealFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm );
MetadataKnnIntFeature metadataKnnIntFeature = new MetadataKnnIntFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm );
MetadataKnnRealFeature metadataKnnRealFeature = new MetadataKnnRealFeature( config.randomSeedQuery, config.dimensionFeatureVectors, config.limitKnnQueries, config.distanceNorm );
Expand All @@ -186,9 +187,14 @@ public void warmUp( ProgressReporter progressReporter, int iterations ) {
if ( config.numberOfSimpleKnnRealFeatureQueries > 0 ) {
executor.executeQuery( simpleKnnRealFeatureBuilder.getNewQuery() );
}
if ( config.numberOfSimpleKnnIdIntFeatureQueries > 0 ) {
executor.executeQuery( simpleKnnIdIntFeatureBuilder.getNewQuery() );

if ( config.numberOfSimpleMetadataQueries > 0 ) {
executor.executeQuery( simpleMetadataBuilder.getNewQuery() );
}

// if ( config.numberOfSimpleKnnIdIntFeatureQueries > 0 ) {
// executor.executeQuery( simpleKnnIdIntFeatureBuilder.getNewQuery() );
// }
if ( config.numberOfSimpleKnnIdRealFeatureQueries > 0 ) {
executor.executeQuery( simpleKnnIdRealFeatureBuilder.getNewQuery() );
}
Expand Down Expand Up @@ -343,7 +349,6 @@ public void analyze( Properties properties ) {
}



private void calculateResults( Properties properties, int templateId, List<Long> time ) {
LongSummaryStatistics summaryStatistics = time.stream().mapToLong( Long::longValue ).summaryStatistics();
double mean = summaryStatistics.getAverage();
Expand All @@ -362,8 +367,6 @@ private void calculateResults( Properties properties, int templateId, List<Long>
}




@Override
public int getNumberOfInsertThreads() {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class KnnBenchConfig extends AbstractConfig {
public final int numberOfEntries;
public final int numberOfSimpleKnnIntFeatureQueries;
public final int numberOfSimpleKnnRealFeatureQueries;
public final int numberOfSimpleMetadataQueries;
public final int numberOfSimpleKnnIdIntFeatureQueries;
public final int numberOfSimpleKnnIdRealFeatureQueries;
public final int numberOfMetadataKnnIntFeatureQueries;
Expand Down Expand Up @@ -69,6 +70,7 @@ public KnnBenchConfig( Properties properties, int multiplier ) {
batchSizeQueries = getIntProperty( properties, "batchSizeQueries" );
numberOfSimpleKnnIntFeatureQueries = getIntProperty( properties, "numberOfSimpleKnnIntFeatureQueries" ) * multiplier;
numberOfSimpleKnnRealFeatureQueries = getIntProperty( properties, "numberOfSimpleKnnRealFeatureQueries" ) * multiplier;
numberOfSimpleMetadataQueries = getIntProperty( properties, "numberOfSimpleMetadataQueries" ) * multiplier;
numberOfSimpleKnnIdIntFeatureQueries = getIntProperty( properties, "numberOfSimpleKnnIdIntFeatureQueries" ) * multiplier;
numberOfSimpleKnnIdRealFeatureQueries = getIntProperty( properties, "numberOfSimpleKnnIdRealFeatureQueries" ) * multiplier;
numberOfMetadataKnnIntFeatureQueries = getIntProperty( properties, "numberOfMetadataKnnIntFeatureQueries" ) * multiplier;
Expand Down Expand Up @@ -118,6 +120,7 @@ public KnnBenchConfig( Map<String, String> cdl ) {
batchSizeQueries = Integer.parseInt( cdl.get( "batchSizeQueries" ) );
numberOfSimpleKnnIntFeatureQueries = Integer.parseInt( cdl.get( "numberOfSimpleKnnIntFeatureQueries" ) );
numberOfSimpleKnnRealFeatureQueries = Integer.parseInt( cdl.get( "numberOfSimpleKnnRealFeatureQueries" ) );
numberOfSimpleMetadataQueries = Integer.parseInt( cdl.get( "numberOfSimpleMetadataQueries" ) );
numberOfSimpleKnnIdIntFeatureQueries = Integer.parseInt( cdl.get( "numberOfSimpleKnnIdIntFeatureQueries" ) );
numberOfSimpleKnnIdRealFeatureQueries = Integer.parseInt( cdl.get( "numberOfSimpleKnnIdRealFeatureQueries" ) );
numberOfMetadataKnnIntFeatureQueries = Integer.parseInt( cdl.get( "numberOfMetadataKnnIntFeatureQueries" ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.polypheny.simpleclient.scenario.knnbench.queryBuilder;


import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import kong.unirest.HttpRequest;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.polypheny.simpleclient.query.Query;
import org.polypheny.simpleclient.query.QueryBuilder;


public class SimpleMetadata extends QueryBuilder {

private static final boolean EXPECT_RESULT = true;

private final long randomSeed;
private final int numOfEntries;

private final Random random;


public SimpleMetadata( long randomSeed, int numOfEntries ) {
this.randomSeed = randomSeed;
this.numOfEntries = numOfEntries;

this.random = new Random( randomSeed );
}


private int getRandomId() {
return this.random.nextInt( this.numOfEntries );
}


@Override
public Query getNewQuery() {
return new SimpleMetadataQuery( this.getRandomId() );
}


private static class SimpleMetadataQuery extends Query {

private static final String SQL = "SELECT id, textdata FROM knn_metadata WHERE id = ";

private final int id;


private SimpleMetadataQuery( int id ) {
super( EXPECT_RESULT );
this.id = id;
}


@Override
public String getSql() {
return SQL + id;
}


@Override
public String getParameterizedSqlQuery() {
return SQL + "?";
}


@Override
public Map<Integer, ImmutablePair<DataTypes, Object>> getParameterValues() {
Map<Integer, ImmutablePair<DataTypes, Object>> map = new HashMap<>();
map.put( 1, new ImmutablePair<>( DataTypes.INTEGER, id ) );
return map;
}


@Override
public HttpRequest<?> getRest() {
return null;
}

}

}

0 comments on commit 72120f0

Please sign in to comment.