Skip to content

Commit

Permalink
GBPTreeIT have more consistent test times
Browse files Browse the repository at this point in the history
Previously there were some that took sub-second, others tens of seconds.
Execution time of most tests were also dependent on how many threads the
machine running it had, this is also improved on.
  • Loading branch information
tinwelint committed Jan 16, 2017
1 parent a7ca610 commit cf3b481
Showing 1 changed file with 16 additions and 16 deletions.
Expand Up @@ -33,7 +33,6 @@
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -101,10 +100,10 @@ public void consistencyCheckAndClose() throws IOException
public void shouldStayCorrectAfterRandomModifications() throws Exception public void shouldStayCorrectAfterRandomModifications() throws Exception
{ {
// GIVEN // GIVEN
GBPTree<MutableLong,MutableLong> index = createIndex( 1024 ); GBPTree<MutableLong,MutableLong> index = createIndex( 256 );
Comparator<MutableLong> keyComparator = layout; Comparator<MutableLong> keyComparator = layout;
Map<MutableLong,MutableLong> data = new TreeMap<>( keyComparator ); Map<MutableLong,MutableLong> data = new TreeMap<>( keyComparator );
int count = 1000; int count = 100;
for ( int i = 0; i < count; i++ ) for ( int i = 0; i < count; i++ )
{ {
data.put( randomKey( random.random() ), randomKey( random.random() ) ); data.put( randomKey( random.random() ), randomKey( random.random() ) );
Expand Down Expand Up @@ -194,7 +193,7 @@ public void shouldReadCorrectlyWhenConcurrentlyInsertingInOrder() throws Throwab
} }


// Read one go, we should see up to highId // Read one go, we should see up to highId
long start = Long.max( 0, upToId - 1000 ); long start = Long.max( 0, upToId - 100 );
long lastSeen = start - 1; long lastSeen = start - 1;
long startTime; long startTime;
long startTimeLeaf; long startTimeLeaf;
Expand Down Expand Up @@ -271,13 +270,14 @@ public void shouldReadCorrectlyWhenConcurrentlyInsertingInOrder() throws Throwab
{ {
assertTrue( readerReadySignal.await( 10, SECONDS ) ); assertTrue( readerReadySignal.await( 10, SECONDS ) );
startSignal.countDown(); startSignal.countDown();
Random random1 = ThreadLocalRandom.current(); Random random = this.random.random();
int inserted = 0; int inserted = 0;
while ( (inserted < 100_000 || numberOfReads.get() < 10_000) && !failHalt.get() ) int wantedNbrOfReads = 10_000 * readers;
while ( (inserted < 10_000 || numberOfReads.get() < wantedNbrOfReads) && !failHalt.get() )
{ {
try ( Writer<MutableLong,MutableLong> writer = index.writer() ) try ( Writer<MutableLong,MutableLong> writer = index.writer() )
{ {
int groupCount = random1.nextInt( 1000 ) + 1; int groupCount = random.nextInt( 1000 ) + 1;
for ( int i = 0; i < groupCount; i++, inserted++ ) for ( int i = 0; i < groupCount; i++, inserted++ )
{ {
MutableLong thing = new MutableLong( inserted ); MutableLong thing = new MutableLong( inserted );
Expand All @@ -286,7 +286,7 @@ public void shouldReadCorrectlyWhenConcurrentlyInsertingInOrder() throws Throwab
} }
} }
// Sleep a little in between update groups (transactions, sort of) // Sleep a little in between update groups (transactions, sort of)
MILLISECONDS.sleep( random1.nextInt( 10 ) + 3 ); MILLISECONDS.sleep( random.nextInt( 10 ) + 3 );
} }
} }
finally finally
Expand Down Expand Up @@ -315,10 +315,10 @@ public void shouldReadCorrectlyWhenConcurrentlyInsertingOutOfOrder() throws Thro
int nbrOfGroups = 10; int nbrOfGroups = 10;
int wantedRangeWidth = 1_000; int wantedRangeWidth = 1_000;
int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups; int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups;
int wantedNbrOfReads = 100_000;


// Readers config // Readers config
int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 ); int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 );
int wantedNbrOfReads = 10_000 * readers;


// Thread communication // Thread communication
AtomicInteger currentWriteIteration = new AtomicInteger( 0 ); AtomicInteger currentWriteIteration = new AtomicInteger( 0 );
Expand Down Expand Up @@ -400,10 +400,10 @@ public void shouldReadCorrectlyWhenConcurrentlyInsertingOutOfOrderAndSeekingBack
int nbrOfGroups = 10; int nbrOfGroups = 10;
int wantedRangeWidth = 1_000; int wantedRangeWidth = 1_000;
int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups; int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups;
int wantedNbrOfReads = 10_000;


// Readers config // Readers config
int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 ); int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 );
int wantedNbrOfReads = 10_000 * readers;


// Thread communication // Thread communication
AtomicInteger currentWriteIteration = new AtomicInteger( 0 ); AtomicInteger currentWriteIteration = new AtomicInteger( 0 );
Expand Down Expand Up @@ -440,7 +440,7 @@ public void shouldReadCorrectlyWhenConcurrentlyInsertingOutOfOrderAndSeekingBack
startSignal.countDown(); startSignal.countDown();
int iteration = currentWriteIteration.get(); int iteration = currentWriteIteration.get();
int writesPerIteration = rangeWidth / nbrOfGroups; int writesPerIteration = rangeWidth / nbrOfGroups;
int nbrOfLeastWantedIterations = 100_000 / writesPerIteration; int nbrOfLeastWantedIterations = 10_000 / writesPerIteration;
while ( !failHalt.get() && while ( !failHalt.get() &&
(numberOfReads.get() < wantedNbrOfReads || iteration < nbrOfLeastWantedIterations) ) (numberOfReads.get() < wantedNbrOfReads || iteration < nbrOfLeastWantedIterations) )
{ {
Expand Down Expand Up @@ -487,10 +487,10 @@ public void shouldReadCorrectlyWhenConcurrentlyRemovingOutOfOrder() throws Throw


// Write group config // Write group config
int nbrOfGroups = 10; int nbrOfGroups = 10;
int wantedRangeWidth = 1_000; int wantedRangeWidth = 100;
int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups; int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups;
long minValue = 0L; long minValue = 0L;
long maxValue = 100_000L; long maxValue = 10_000L;


// Readers config // Readers config
int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 ); int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 );
Expand Down Expand Up @@ -576,10 +576,10 @@ public void shouldReadCorrectlyWhenConcurrentlyRemovingOutOfOrderBackwards() thr


// Write group config // Write group config
int nbrOfGroups = 10; int nbrOfGroups = 10;
int wantedRangeWidth = 1_00; int wantedRangeWidth = 100;
int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups; int rangeWidth = wantedRangeWidth - wantedRangeWidth % nbrOfGroups;
long minValue = 0L; long minValue = 0L;
long maxValue = 1_000L; long maxValue = 10_000L;


// Readers config // Readers config
int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 ); int readers = max( 1, Runtime.getRuntime().availableProcessors() - 1 );
Expand Down Expand Up @@ -638,7 +638,7 @@ public void shouldReadCorrectlyWhenConcurrentlyRemovingOutOfOrderBackwards() thr
} }
iteration = currentWriteIteration.addAndGet( 2 ); iteration = currentWriteIteration.addAndGet( 2 );
// Sleep a little in between update groups (transactions, sort of) // Sleep a little in between update groups (transactions, sort of)
MILLISECONDS.sleep( random.nextInt( 3,13 ) ); MILLISECONDS.sleep( random.nextInt( 3, 13 ) );
} }
} }
finally finally
Expand Down

0 comments on commit cf3b481

Please sign in to comment.