Skip to content

MvStore upgrade and tuning #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2-mvstore</artifactId>
<version>1.4.200</version>
<version>2.3.232</version>
</dependency>
<dependency>
<groupId>io.github.microutils</groupId>
82 changes: 63 additions & 19 deletions src/main/java/org/lmdbjava/bench/MvStore.java
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* #%L
* LmdbJava Benchmarks
* %%
* Copyright (C) 2016 - 2022 The LmdbJava Open Source Project
* Copyright (C) 2016 - 2024 The LmdbJava Open Source Project
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,12 +31,17 @@

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.nio.ByteBuffer;
import java.util.Arrays;

import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.h2.mvstore.Cursor;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.WriteBuffer;
import org.h2.mvstore.type.BasicDataType;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
@@ -60,10 +65,10 @@ public class MvStore {
@Benchmark
public void readCrc(final Reader r, final Blackhole bh) {
r.crc.reset();
final Iterator<byte[]> iter = r.map.keyIterator(null);
while (iter.hasNext()) {
final byte[] k = iter.next();
final byte[] v = r.map.get(k);
final Cursor<byte[], byte[]> cursor = r.map.cursor(null, null, false);
while (cursor.hasNext()) {
final byte[] k = cursor.next();
final byte[] v = cursor.getValue();
r.crc.update(k);
r.crc.update(v);
}
@@ -78,34 +83,35 @@ public void readKey(final Reader r, final Blackhole bh) {
} else {
r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key));
}
bh.consume(r.map.get(copyOf(r.wkb.byteArray(), r.keySize)));
bh.consume(r.map.get(r.wkb.byteArray()));
}
}

@Benchmark
public void readRev(final Reader r, final Blackhole bh) {
for (long i = r.map.sizeAsLong() - 1; i >= 0; i--) {
final byte[] k = r.map.getKey(i);
bh.consume(r.map.get(k));
final Cursor<byte[], byte[]> cursor = r.map.cursor(null, null, true);
while (cursor.hasNext()) {
cursor.next();
bh.consume(cursor.getValue());
}
}

@Benchmark
public void readSeq(final Reader r, final Blackhole bh) {
final Iterator<byte[]> iter = r.map.keyIterator(null);
while (iter.hasNext()) {
final byte[] k = iter.next();
bh.consume(r.map.get(k));
final Cursor<byte[], byte[]> cursor = r.map.cursor(null, null, false);
while (cursor.hasNext()) {
cursor.next();
bh.consume(cursor.getValue());
}
}

@Benchmark
public void readXxh64(final Reader r, final Blackhole bh) {
long result = 0;
final Iterator<byte[]> iter = r.map.keyIterator(null);
while (iter.hasNext()) {
final byte[] k = iter.next();
final byte[] v = r.map.get(k);
final Cursor<byte[], byte[]> cursor = r.map.cursor(null, null, false);
while (cursor.hasNext()) {
final byte[] k = cursor.next();
final byte[] v = cursor.getValue();
result += xx_r39().hashBytes(k);
result += xx_r39().hashBytes(v);
}
@@ -143,7 +149,11 @@ public void setup(final BenchmarkParams b) throws IOException {
.fileName(new File(tmp, "mvstore.db").getAbsolutePath())
.autoCommitDisabled()
.open();
map = s.openMap("ba2ba");
final MVMap.Builder<byte[], byte[]> builder = new MVMap.Builder<byte[], byte[]>()
.keyType(BADataType.INSTANCE)
.valueType(BADataType.INSTANCE)
.singleWriter();
map = s.openMap("ba2ba", builder);
}

@Override
@@ -212,4 +222,38 @@ public void teardown() throws IOException {
}
}

public static final class BADataType extends BasicDataType<byte[]> {
public static final BADataType INSTANCE = new BADataType();

private BADataType() { }

@Override
public int getMemory(final byte[] data) {
return data.length;
}

@Override
public void write(final WriteBuffer buff, final byte[] data) {
buff.putVarInt(data.length);
buff.put(data);
}

@Override
public byte[] read(final ByteBuffer buff) {
final int size = DataUtils.readVarInt(buff);
final byte[] data = new byte[size];
buff.get(data);
return data;
}

@Override
public byte[][] createStorage(final int size) {
return new byte[size][];
}

@Override
public int compare(final byte[] one, final byte[] two) {
return Arrays.compare(one, two);
}
}
}