mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Consolidate segment headers to reduce TLB misses. Re-tune the calculated number of segments based on the size of data.
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -34,32 +33,52 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class EntryCountMapTest {
|
||||
double score = 0;
|
||||
int scoreCount = 0;
|
||||
|
||||
static File getPersistenceFile() {
|
||||
String TMP = System.getProperty("java.io.tmpdir");
|
||||
File file = new File(TMP + "/small-chm-test" + System.nanoTime());
|
||||
file.deleteOnExit();
|
||||
return file;
|
||||
}
|
||||
|
||||
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
|
||||
long entries, int segments, int entrySize) throws IOException {
|
||||
return getSharedMap(entries, segments, entrySize, OF_4_BYTES);
|
||||
}
|
||||
|
||||
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
|
||||
long entries, int segments, int entrySize, Alignment alignment)
|
||||
throws IOException {
|
||||
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> mapBuilder = OffHeapUpdatableChronicleMapBuilder.of(CharSequence.class, LongValue.class)
|
||||
.entries(entries)
|
||||
.minSegments(segments)
|
||||
.entrySize(entrySize)
|
||||
.entryAndValueAlignment(alignment)
|
||||
.file(getPersistenceFile());
|
||||
return mapBuilder.create();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerySmall() throws Exception {
|
||||
int s = 1, i = 1;
|
||||
// regression test.
|
||||
testEntriesMaxSize(s, 1, 1, i);
|
||||
testEntriesMaxSize(s, 2, 2, i);
|
||||
testEntriesMaxSize(s, 4, 4, i);
|
||||
testEntriesMaxSize(s, 8, 8, i);
|
||||
testEntriesMaxSize(s, 16, 16, i);
|
||||
testEntriesMaxSize(s, 32, 32, i);
|
||||
testEntriesMaxSize(s, 64, 64, i);
|
||||
s = 2;
|
||||
testEntriesMaxSize(s, 4, 8, i);
|
||||
testEntriesMaxSize(s, 8, 16, i);
|
||||
testEntriesMaxSize(s, 16, 32, i);
|
||||
testEntriesMaxSize(s, 32, 64, i);
|
||||
testEntriesMaxSize(s, 2, 4, i);
|
||||
testEntriesMaxSize(s, 4, 6, i);
|
||||
testEntriesMaxSize(s, 8, 13, i);
|
||||
testEntriesMaxSize(s, 16, 55, i); // todo fix the max.
|
||||
testEntriesMaxSize(s, 32, 82, i); // todo fix the max.
|
||||
testEntriesMaxSize(s, 64, 128, i);
|
||||
testEntriesMaxSize(s, 128, 256, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSmall() throws Exception {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// regression test.
|
||||
for (int s : new int[]{1, 2, 4, 8}) {
|
||||
if (s <= 4)
|
||||
testEntriesMaxSize(s, 128, 256, i);
|
||||
testEntriesMaxSize(s, 256, 510, i);
|
||||
testEntriesMaxSize(s, 512, 1010, i);
|
||||
testEntriesMaxSize(s, 1000, 1730, i);
|
||||
@@ -68,7 +87,7 @@ public class EntryCountMapTest {
|
||||
testEntriesMaxSize(s, 5000, 6800, i);
|
||||
testEntriesMaxSize(s, 8000, 10600, i);
|
||||
testEntriesMaxSize(s, 12000, 16000, i);
|
||||
testEntriesMaxSize(s, 16000, 21000, i);
|
||||
testEntriesMaxSize(s, 16000, 21300, i);
|
||||
}
|
||||
}
|
||||
// hyperbolic average gives more weight to small numbers.
|
||||
@@ -87,14 +106,14 @@ public class EntryCountMapTest {
|
||||
testEntriesMaxSize(s, 5000, 7100, i);
|
||||
testEntriesMaxSize(s, 8000, 10200, i);
|
||||
testEntriesMaxSize(s, 12000, 16000, i);
|
||||
testEntriesMaxSize(s, 16000, 21000, i);
|
||||
testEntriesMaxSize(s, 16000, 21300, i);
|
||||
s = 32;
|
||||
testEntriesMaxSize(s, 2000, 3900, i);
|
||||
testEntriesMaxSize(s, 4000, 5900, i);
|
||||
testEntriesMaxSize(s, 5000, 7900, i);
|
||||
testEntriesMaxSize(s, 8000, 12000, i);
|
||||
testEntriesMaxSize(s, 12000, 15900, i);
|
||||
testEntriesMaxSize(s, 16000, 21200, i);
|
||||
testEntriesMaxSize(s, 16000, 21300, i);
|
||||
testEntriesMaxSize(s, 32000, 42200, i);
|
||||
s = 64;
|
||||
testEntriesMaxSize(s, 5000, 7550, i);
|
||||
@@ -134,9 +153,6 @@ public class EntryCountMapTest {
|
||||
System.out.printf("Score: %.2f%n", scoreCount / score);
|
||||
}
|
||||
|
||||
double score = 0;
|
||||
int scoreCount = 0;
|
||||
|
||||
private void testEntriesMaxSize(int segments, int minSize, int maxSize, int seed) throws IOException {
|
||||
int counter = minSize + new Random(seed + segments * 1000).nextInt(9999);
|
||||
ChronicleMap<CharSequence, LongValue> map = getSharedMap(minSize, segments, 32);
|
||||
@@ -167,7 +183,7 @@ public class EntryCountMapTest {
|
||||
System.out.println("segs: " + segments + " min: " + minSize + " was " + map.size() + " "
|
||||
+ Arrays.toString(a)
|
||||
+ " sum: " + sum(a));
|
||||
assertTrue("min: " + minSize + ", size: " + map.size(), condition);
|
||||
assertTrue("seg: " + segments + ", min: " + minSize + ", size: " + map.size(), condition);
|
||||
}
|
||||
} finally {
|
||||
map.close();
|
||||
@@ -182,29 +198,5 @@ public class EntryCountMapTest {
|
||||
return sum;
|
||||
}
|
||||
|
||||
static File getPersistenceFile() {
|
||||
String TMP = System.getProperty("java.io.tmpdir");
|
||||
File file = new File(TMP + "/small-chm-test" + System.nanoTime());
|
||||
file.deleteOnExit();
|
||||
return file;
|
||||
}
|
||||
|
||||
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
|
||||
long entries, int segments, int entrySize) throws IOException {
|
||||
return getSharedMap(entries, segments, entrySize, OF_4_BYTES);
|
||||
}
|
||||
|
||||
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
|
||||
long entries, int segments, int entrySize, Alignment alignment)
|
||||
throws IOException {
|
||||
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> mapBuilder = OffHeapUpdatableChronicleMapBuilder.of(CharSequence.class, LongValue.class)
|
||||
.entries(entries)
|
||||
.minSegments(segments)
|
||||
.entrySize(entrySize)
|
||||
.entryAndValueAlignment(alignment)
|
||||
.file(getPersistenceFile());
|
||||
return mapBuilder.create();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user