Skip to content

Commit

Permalink
HSEARCH-3827 Enable comparison of multiple backend configurations in …
Browse files Browse the repository at this point in the history
…benchmarks
  • Loading branch information
yrodiere authored and fax4ever committed Feb 17, 2020
1 parent 2789bdb commit 3de5a26
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;

import org.hibernate.search.engine.cfg.BackendSettings;
import org.hibernate.search.engine.cfg.EngineSettings;
import org.hibernate.search.engine.cfg.spi.ConfigurationPropertyChecker;
import org.hibernate.search.engine.cfg.spi.ConfigurationPropertySource;
Expand Down Expand Up @@ -46,11 +47,19 @@ public void startHibernateSearch(TemporaryFileHolder temporaryFileHolder) throws
Map<String, Object> baseProperties = new LinkedHashMap<>();
baseProperties.put( EngineSettings.DEFAULT_BACKEND, BACKEND_NAME );

ConfigurationPropertySource configurationFromParameter =
ConfigurationPropertySource.fromMap( stringToMap( getConfigurationParameter() ) );

ConfigurationPropertySource propertySource = ConfigurationPropertySource.fromMap( baseProperties )
.withOverride(
getDefaultBackendProperties( temporaryFileHolder )
// Allow overrides at the backend level using system properties
.withOverride( ConfigurationPropertySource.system() )
// Allow multiple backend configurations to be tested using a benchmark parameter
// > Apply the configuration at the backend level
.withOverride( configurationFromParameter )
// > Apply the configuration at the index level (for convenience)
.withOverride( configurationFromParameter.withPrefix( BackendSettings.INDEX_DEFAULTS ) )
.withPrefix( EngineSettings.BACKENDS + "." + BACKEND_NAME )
);

Expand Down Expand Up @@ -110,7 +119,22 @@ public List<MappedIndex> getIndexes() {
return indexes;
}

protected final Map<String, String> stringToMap(String settings) {
String[] settingsSplit = settings.split( "&" );
Map<String, String> map = new LinkedHashMap<>();
for ( String keyValue : settingsSplit ) {
if ( keyValue.isEmpty() ) {
continue;
}
String[] keyValueSplit = keyValue.split( "=" );
map.put( keyValueSplit[0], keyValueSplit[1] );
}
return map;
}

protected abstract ConfigurationPropertySource getDefaultBackendProperties(TemporaryFileHolder temporaryFileHolder)
throws IOException;

protected abstract String getConfigurationParameter();

}
Expand Up @@ -18,12 +18,26 @@
import org.hibernate.search.integrationtest.performance.backend.base.testsupport.filesystem.TemporaryFileHolder;
import org.hibernate.search.integrationtest.performance.backend.base.testsupport.index.AbstractBackendHolder;

import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

@State(Scope.Benchmark)
public class ElasticsearchBackendHolder extends AbstractBackendHolder {

/**
* A list of configuration properties to apply to the backend and indexes.
* <p>
* Format: {@code <key>=<value>&<key2>=<value2>} (etc.).
* Multiple configurations can be tested by providing multiple values for this parameter,
* e.g. {@code foo=1&bar=2,foo=2&bar=1} for two configurations setting {@code foo} and {@code bar} to different values.
* <p>
* Note that configuration properties are applied both at the backend level and at the index level,
* so using the "index_defaults." prefix is optional when setting index-level properties.
*/
@Param({ "", "max_connections_per_route=1" })
private String configuration;

@Override
protected ConfigurationPropertySource getDefaultBackendProperties(TemporaryFileHolder temporaryFileHolder) {
Map<String, Object> map = new LinkedHashMap<>();
Expand All @@ -44,4 +58,9 @@ protected ConfigurationPropertySource getDefaultBackendProperties(TemporaryFileH

return ConfigurationPropertySource.fromMap( map );
}

@Override
protected String getConfigurationParameter() {
return configuration;
}
}
Expand Up @@ -47,6 +47,11 @@ public void test() throws RunnerException {
.warmupIterations( 0 )
.measurementIterations( 1 )
.measurementTime( TimeValue.seconds( 1 ) )
.param(
"configuration",
"",
"max_connections_per_route=30"
)
.param( "initialIndexSize", "100" )
.param( "batchSize", "10" )
.param( "maxResults", "10" )
Expand Down
Expand Up @@ -16,12 +16,26 @@
import org.hibernate.search.integrationtest.performance.backend.base.testsupport.filesystem.TemporaryFileHolder;
import org.hibernate.search.integrationtest.performance.backend.base.testsupport.index.AbstractBackendHolder;

import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

@State(Scope.Benchmark)
public class LuceneBackendHolder extends AbstractBackendHolder {

/**
* A list of configuration properties to apply to the backend and indexes.
* <p>
* Format: {@code <key>=<value>&<key2>=<value2>} (etc.).
* Multiple configurations can be tested by providing multiple values for this parameter,
* e.g. {@code foo=1&bar=2,foo=2&bar=1} for two configurations setting {@code foo} and {@code bar} to different values.
* <p>
* Note that configuration properties are applied both at the backend level and at the index level,
* so using the "index_defaults." prefix is optional when setting index-level properties.
*/
@Param({ "", "io.commit_interval=1000", "io.commit_interval=1000&io.refresh_interval=1000", "io.strategy=debug" })
private String configuration;

@Override
protected ConfigurationPropertySource getDefaultBackendProperties(TemporaryFileHolder temporaryFileHolder)
throws IOException {
Expand All @@ -33,4 +47,9 @@ protected ConfigurationPropertySource getDefaultBackendProperties(TemporaryFileH

return ConfigurationPropertySource.fromMap( map );
}

@Override
protected String getConfigurationParameter() {
return configuration;
}
}
Expand Up @@ -30,6 +30,11 @@ public void test() throws RunnerException {
.warmupIterations( 0 )
.measurementIterations( 1 )
.measurementTime( TimeValue.seconds( 1 ) )
.param(
"configuration",
"",
"io.commit_interval=100&io.refresh_interval=100"
)
.param( "initialIndexSize", "100" )
.param( "batchSize", "10" )
.param( "maxResults", "10" )
Expand Down

0 comments on commit 3de5a26

Please sign in to comment.