Skip to content

Commit

Permalink
Limit random access in compressed column tests. (apache#4414)
Browse files Browse the repository at this point in the history
* Limit random access in compressed column tests.

Random access leads to lots of block decompressions for reading single elements,
which is time prohibitive for the large column tests. For those tests, limit the
number of randomly accessed elements to 1000.

* Random -> ThreadLocalRandom
  • Loading branch information
gianm authored Jun 15, 2017
1 parent bf537f9 commit 054cf8a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.google.common.base.Supplier;
import com.google.common.io.ByteSink;
import com.google.common.primitives.Floats;
import com.google.common.primitives.Ints;
import io.druid.java.util.common.guava.CloseQuietly;
import it.unimi.dsi.fastutil.ints.IntArrays;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -36,9 +36,9 @@
import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -167,9 +167,10 @@ private void assertIndexMatchesVals(IndexedFloats indexed, float[] vals)
indices[i] = i;
}

Collections.shuffle(Ints.asList(indices));
// random access
for (int i = 0; i < indexed.size(); ++i) {
// random access, limited to 1000 elements for large lists (every element would take too long)
IntArrays.shuffle(indices, ThreadLocalRandom.current());
final int limit = Math.min(indexed.size(), 1000);
for (int i = 0; i < limit; ++i) {
int k = indices[i];
Assert.assertEquals(vals[k], indexed.get(k), DELTA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.primitives.Longs;
import io.druid.java.util.common.guava.CloseQuietly;
import io.druid.segment.CompressedPools;
import it.unimi.dsi.fastutil.ints.IntArrays;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -34,9 +35,9 @@
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.channels.Channels;
import java.util.Collections;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -330,9 +331,10 @@ private void assertIndexMatchesVals()
indices[i] = i;
}

Collections.shuffle(Ints.asList(indices));
// random access
for (int i = 0; i < indexed.size(); ++i) {
// random access, limited to 1000 elements for large lists (every element would take too long)
IntArrays.shuffle(indices, ThreadLocalRandom.current());
final int limit = Math.min(indexed.size(), 1000);
for (int i = 0; i < limit; ++i) {
int k = indices[i];
Assert.assertEquals(vals[k], indexed.get(k), 0.0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import com.google.common.base.Supplier;
import com.google.common.io.ByteSink;
import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs;
import io.druid.java.util.common.guava.CloseQuietly;
import it.unimi.dsi.fastutil.ints.IntArrays;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -36,9 +36,9 @@
import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -189,9 +189,10 @@ private void assertIndexMatchesVals(IndexedLongs indexed, long[] vals)
indices[i] = i;
}

Collections.shuffle(Ints.asList(indices));
// random access
for (int i = 0; i < indexed.size(); ++i) {
// random access, limited to 1000 elements for large lists (every element would take too long)
IntArrays.shuffle(indices, ThreadLocalRandom.current());
final int limit = Math.min(indexed.size(), 1000);
for (int i = 0; i < limit; ++i) {
int k = indices[i];
Assert.assertEquals(vals[k], indexed.get(k));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.common.primitives.Longs;
import io.druid.java.util.common.guava.CloseQuietly;
import io.druid.segment.CompressedPools;
import it.unimi.dsi.fastutil.ints.IntArrays;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -38,11 +39,11 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -351,7 +352,7 @@ private void assertIndexMatchesVals()
{
Assert.assertEquals(vals.length, indexed.size());

// sequential access
// sequential access of every element
int[] indices = new int[vals.length];
for (int i = 0; i < indexed.size(); ++i) {
final int expected = vals[i];
Expand All @@ -360,9 +361,10 @@ private void assertIndexMatchesVals()
indices[i] = i;
}

Collections.shuffle(Ints.asList(indices));
// random access
for (int i = 0; i < indexed.size(); ++i) {
// random access, limited to 1000 elements for large lists (every element would take too long)
IntArrays.shuffle(indices, ThreadLocalRandom.current());
final int limit = Math.min(indexed.size(), 1000);
for (int i = 0; i < limit; ++i) {
int k = indices[i];
Assert.assertEquals(vals[k], indexed.get(k));
}
Expand Down

0 comments on commit 054cf8a

Please sign in to comment.