Skip to content

Commit

Permalink
HSEARCH-1604 Enabling all modules but having the performance ones ret…
Browse files Browse the repository at this point in the history
…urn quickly when not running the _perf_ profile
  • Loading branch information
Sanne committed May 16, 2014
1 parent d32e256 commit 5ebab73
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 28 deletions.
Expand Up @@ -76,4 +76,8 @@ public static String getIndexDirectory(Class<?> testClass) {
log.debugf( "Using %s as index directory.", indexDirPath );
return indexDirPath;
}

public static boolean arePerformanceTestsEnabled() {
return Boolean.getBoolean( "org.hibernate.search.enable_performance_tests" );
}
}
Expand Up @@ -19,19 +19,22 @@

import org.hibernate.SessionFactory;
import org.hibernate.search.test.performance.task.AbstractTask;
import org.hibernate.search.testsupport.TestConstants;

/**
* @author Tomas Hradec
*/
public class TestContext {

public static final boolean VERBOSE = true;
public static final boolean MEASURE_MEMORY = true;
public static final boolean MEASURE_TASK_TIME = true;
private static final Boolean PERFORMANCE_ENABLED = TestConstants.arePerformanceTestsEnabled();

public static final boolean VERBOSE = PERFORMANCE_ENABLED;
public static final boolean MEASURE_MEMORY = PERFORMANCE_ENABLED;
public static final boolean MEASURE_TASK_TIME = PERFORMANCE_ENABLED;
public static final boolean ASSERT_QUERY_RESULTS = true;
public static final boolean CHECK_INDEX_STATE = true;
public static final int MAX_AUTHORS = 1000;
public static final int THREADS_COUNT = 10;
public static final int THREADS_COUNT = PERFORMANCE_ENABLED ? 10 : 2;

public final SessionFactory sf;
public final TestScenario scenario;
Expand Down
Expand Up @@ -119,6 +119,7 @@ private static void printTaskInfo(TestContext ctx, PrintWriter out) {
private static void printEnvInfo(TestContext ctx, PrintWriter out) {
out.println( "" );
out.println( "TEST CONFIGURATION" );
out.println( " measure performance : " + TestConstants.arePerformanceTestsEnabled() );
out.println( " threads : " + THREADS_COUNT );
out.println( " measured cycles : " + ctx.scenario.measuredCyclesCount );
out.println( " warmup cycles : " + ctx.scenario.warmupCyclesCount );
Expand Down
Expand Up @@ -35,13 +35,16 @@
import org.hibernate.search.test.performance.task.UpdateBookTotalSoldTask;
import org.hibernate.search.test.performance.util.BatchCallback;
import org.hibernate.search.test.performance.util.BatchSupport;
import org.hibernate.search.testsupport.TestConstants;

/**
* @author Tomas Hradec
*/
public abstract class TestScenario {

public final long initialOffset = 1000 * 1000;
private static final Boolean PERFORMANCE_ENABLED = TestConstants.arePerformanceTestsEnabled();

public final long initialOffset;
public final long initialAutorCount;
public final long initialBookCount;
public final long warmupCyclesCount;
Expand All @@ -52,10 +55,20 @@ public abstract class TestScenario {
public final StopWatch warmupStopWatch = new StopWatch();

public TestScenario() {
this.initialAutorCount = 10 * 1000;
this.initialBookCount = 1000 * 1000;
this.warmupCyclesCount = 100;
this.measuredCyclesCount = 1000;
if ( PERFORMANCE_ENABLED ) {
this.initialAutorCount = 10 * 1000;
this.initialBookCount = 1000 * 1000;
this.warmupCyclesCount = 100;
this.measuredCyclesCount = 1000;
initialOffset = 1000 * 1000;
}
else {
this.initialAutorCount = 10;
this.initialBookCount = 100;
this.warmupCyclesCount = 1;
this.measuredCyclesCount = 1;
this.initialOffset = 100;
}
}

public TestScenario(long initialAutorCount, long initialBookCount, long warmupCyclesCount, long measuredCyclesCount) {
Expand All @@ -64,6 +77,7 @@ public TestScenario(long initialAutorCount, long initialBookCount, long warmupCy
this.initialBookCount = initialBookCount;
this.warmupCyclesCount = warmupCyclesCount;
this.measuredCyclesCount = measuredCyclesCount;
this.initialOffset = 1000 * 1000;
}

public Properties getHibernateProperties() {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.hibernate.search.backend.spi.Worker;
import org.hibernate.search.engine.spi.SearchFactoryImplementor;
import org.hibernate.search.query.engine.spi.EntityInfo;
import org.hibernate.search.testsupport.TestConstants;
import org.hibernate.search.testsupport.TestForIssue;
import org.hibernate.search.testsupport.junit.SearchFactoryHolder;
import org.hibernate.search.testsupport.setup.TransactionContextForTest;
Expand All @@ -41,14 +42,16 @@
@TestForIssue(jiraKey = "HSEARCH-1317")
public class ReadWriteParallelismTest {

private static final int THREAD_NUMBER = 30;
private static final Boolean PERFORMANCE_ENABLED = TestConstants.arePerformanceTestsEnabled();

private static final int THREAD_NUMBER = PERFORMANCE_ENABLED ? 30 : 1;

/**
* The values below (as committed in source code) are not right for measurement!
* We keep them reasonably low for a reasonably quick feedback from test builds.
*/
private static final int WARM_UP_SECONDS = 20;
private static final int FULL_RUN_SECONDS = 240;
private static final int WARM_UP_SECONDS = PERFORMANCE_ENABLED ? 20 : 0;
private static final int FULL_RUN_SECONDS = PERFORMANCE_ENABLED ? 240 : 0;

private static final AtomicBoolean failures = new AtomicBoolean( false );
private static final AtomicBoolean running = new AtomicBoolean( true );
Expand Down
Expand Up @@ -58,12 +58,12 @@ public void tearDown() throws Exception {

@Test
public void testConcurrency() throws Exception {
int nThreads = 15;
int nThreads = PERFORMANCE_TESTS_ENABLED ? 15 : 1;
ExecutorService es = Executors.newFixedThreadPool( nThreads );
Work work = new Work( getSessionFactory() );
ReverseWork reverseWork = new ReverseWork( getSessionFactory() );
long start = System.nanoTime();
int iteration = 100;
int iteration = PERFORMANCE_TESTS_ENABLED ? 100 : 1;
for ( int i = 0; i < iteration; i++ ) {
es.execute( work );
es.execute( reverseWork );
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.apache.lucene.util.Version;
import org.hibernate.search.cfg.Environment;
import org.hibernate.search.test.SearchTestBase;
import org.hibernate.search.testsupport.TestConstants;
import org.hibernate.search.util.impl.FileHelper;
import org.junit.After;
import org.junit.Before;
Expand All @@ -31,16 +32,20 @@
*/
public abstract class ReaderPerformance extends SearchTestBase {


private static final Boolean PERFORMANCE_ENABLED = TestConstants.arePerformanceTestsEnabled();

//more iterations for more reliable measures:
private static final int TOTAL_WORK_BATCHES = 10;
private static final int TOTAL_WORK_BATCHES = PERFORMANCE_ENABLED ? 10 : 0;
//the next 3 define the kind of workload mix to test on:
private static final int SEARCHERS_PER_BATCH = 10;
private static final int SEARCHERS_PER_BATCH = PERFORMANCE_ENABLED ? 10 : 1;
private static final int UPDATES_PER_BATCH = 2;
private static final int INSERTIONS_PER_BATCH = 1;
private static final int INDEX_ELEMENTS = PERFORMANCE_ENABLED ? 5000000 : 2;

private static final int WORKER_THREADS = 20;
private static final int WORKER_THREADS = PERFORMANCE_ENABLED ? 20 : 1;

private static final int WARM_UP_CYCLES = 6;
private static final int WARM_UP_CYCLES = PERFORMANCE_ENABLED ? 6 : 1;

@Override
@Before
Expand Down Expand Up @@ -77,7 +82,7 @@ private void buildBigIndex() throws InterruptedException, IOException {
IndexWriter iw = new IndexWriter( directory, cfg );
IndexFillRunnable filler = new IndexFillRunnable( iw );
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool( WORKER_THREADS );
for ( int batch = 0; batch <= 5000000; batch++ ) {
for ( int batch = 0; batch <= INDEX_ELEMENTS; batch++ ) {
executor.execute( filler );
}
executor.shutdown();
Expand Down
Expand Up @@ -79,9 +79,10 @@ protected Class<?>[] getAnnotatedClasses() {

@Test
public void testConcurrency() throws Exception {
final int numberDetectives = PERFORMANCE_TESTS_ENABLED ? 5000 : 5;
Session s = openSession();
Transaction tx = s.beginTransaction();
for ( int index = 0; index < 5000; index++ ) {
for ( int index = 0; index < numberDetectives; index++ ) {
Detective detective = new Detective();
detective.setName( "John Doe " + index );
detective.setBadge( "123455" + index );
Expand All @@ -103,14 +104,12 @@ public void testConcurrency() throws Exception {
tx.commit();
s.close();

Thread.sleep( 1000 );

int nThreads = 15;
int nThreads = PERFORMANCE_TESTS_ENABLED ? 15 : 1;
ExecutorService es = Executors.newFixedThreadPool( nThreads );
Work work = new Work( getSessionFactory() );
ReverseWork reverseWork = new ReverseWork( getSessionFactory() );
long start = System.nanoTime();
int iteration = 100;
int iteration = PERFORMANCE_TESTS_ENABLED ? 100 : 1;
log.info( "Starting worker threads." );
for ( int i = 0; i < iteration; i++ ) {
es.execute( work );
Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.search.engine.SearchFactory;
import org.hibernate.search.engine.spi.SearchFactoryImplementor;
import org.hibernate.search.testsupport.TestConstants;
import org.hibernate.testing.junit4.CustomRunner;
import org.junit.After;
import org.junit.Before;
Expand All @@ -28,6 +29,9 @@
*/
@RunWith(CustomRunner.class)
public abstract class SearchTestBase implements TestResourceManager {

protected static final Boolean PERFORMANCE_TESTS_ENABLED = TestConstants.arePerformanceTestsEnabled();

// access only via getter, since instance gets lazily initalized
private DefaultTestResourceManager testResourceManager;

Expand Down
9 changes: 5 additions & 4 deletions pom.xml
Expand Up @@ -708,7 +708,7 @@
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>deploy</goals>
<releaseProfiles>docbook,dist,perf</releaseProfiles>
<releaseProfiles>docbook,dist</releaseProfiles>
<arguments>-DskipTests</arguments>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
Expand Down Expand Up @@ -823,6 +823,7 @@
<!-- See HSEARCH-1444 -->
<hibernate.service.allow_crawling>false</hibernate.service.allow_crawling>
<com.sun.management.jmxremote>true</com.sun.management.jmxremote>
<org.hibernate.search.enable_performance_tests>${org.hibernate.search.enable_performance_tests}</org.hibernate.search.enable_performance_tests>
</systemPropertyVariables>
<additionalClasspathElements>
<!-- Needed by Byteman to load the agent on demand -->
Expand Down Expand Up @@ -1045,9 +1046,9 @@

<profile>
<id>perf</id>
<modules>
<module>integrationtest/sandbox</module>
</modules>
<properties>
<org.hibernate.search.enable_performance_tests>true</org.hibernate.search.enable_performance_tests>
</properties>
</profile>

<!-- =============================== -->
Expand Down

0 comments on commit 5ebab73

Please sign in to comment.