mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-171 HCOLL-206 HCOLL-247 improved hashing algorithm (now murmur3), implemented ByteBufferInterop, some improvements in existing marshallers
This commit is contained in:
@@ -626,14 +626,11 @@ public class CHMUseCasesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("HCOLL-247 automatically register ByteBufferMarshaller")
|
||||
@Test
|
||||
public void testByteBufferByteBufferDefaultKeyValueMarshaller() throws ExecutionException,
|
||||
InterruptedException {
|
||||
try (ChronicleMap<ByteBuffer, ByteBuffer> map = ChronicleMapBuilder
|
||||
.of(ByteBuffer.class, ByteBuffer.class)
|
||||
// .keyMarshaller(ByteBufferMarshaller.INSTANCE)
|
||||
// .valueMarshaller(ByteBufferMarshaller.INSTANCE)
|
||||
.keySize(8)
|
||||
.valueSize(8)
|
||||
.maxEntryOversizeFactor(1)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.lang.MemoryUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MarkTest {
|
||||
|
||||
static int ENTRIES = 25_000_000;
|
||||
|
||||
@Test
|
||||
public void inMemoryTest() {
|
||||
test(new Function<ChronicleMapBuilder<Integer, Integer>, ChronicleMap<Integer, Integer>>() {
|
||||
@Override
|
||||
public ChronicleMap<Integer, Integer> apply(
|
||||
ChronicleMapBuilder<Integer, Integer> builder) {
|
||||
return builder.create();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistedTest() {
|
||||
final File db = Paths.get(System.getProperty("java.io.tmpdir"), "mark").toFile();
|
||||
try {
|
||||
test(new Function<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>>() {
|
||||
@Override
|
||||
public ChronicleMap<Integer, Integer> apply(
|
||||
ChronicleMapBuilder<Integer, Integer> builder) {
|
||||
try {
|
||||
return builder.createPersistedTo(db);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
System.out.println(MemoryUnit.BYTES.toMegabytes(db.length()) + " MB");
|
||||
assertTrue("ChronicleMap of 25 million int-int entries should be lesser than 400MB",
|
||||
db.length() < MemoryUnit.MEGABYTES.toBytes(400));
|
||||
} finally {
|
||||
db.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Function<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>> createMap) {
|
||||
long ms = System.currentTimeMillis();
|
||||
double entriesWithMargin = ENTRIES * 1.1;
|
||||
long actualEntriesPerSegment = (1L << 17) / 3L;
|
||||
try (ChronicleMap<Integer, Integer> map = createMap.apply(ChronicleMapBuilder
|
||||
.of(Integer.class, Integer.class)
|
||||
.actualSegments((int) (entriesWithMargin / actualEntriesPerSegment))
|
||||
.actualEntriesPerSegment(actualEntriesPerSegment)
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true))) {
|
||||
|
||||
Random r = ThreadLocalRandom.current();
|
||||
for (int i = 0; i < ENTRIES; i++) {
|
||||
map.put(r.nextInt(), r.nextInt());
|
||||
}
|
||||
}
|
||||
System.out.println(System.currentTimeMillis() - ms);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user