pgm: add write stats to BenchmarkReftable

Usage:

  git ls-remote https://gerrit.googlesource.com/gerrit > lsr

  bazel build org.eclipse.jgit.pgm:jgit && rm -rf /tmp/reftable* && \
    ./bazel-bin/org.eclipse.jgit.pgm/jgit debug-benchmark-reftable \
    --test write_stack lsr /tmp/reftable

On my Lenovo x250 laptop, this yields about 1ms per ref write.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I31c74a08026ba188a3256ef6862dae9d85e6d5ef
This commit is contained in:
Han-Wen Nienhuys 2019-11-13 15:23:01 -08:00 committed by Matthias Sohn
parent a8f4bf6abe
commit 0356613f48
1 changed files with 36 additions and 1 deletions

View File

@ -51,14 +51,18 @@
import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import org.eclipse.jgit.internal.storage.file.FileReftableStack;
import org.eclipse.jgit.internal.storage.io.BlockSource;
import org.eclipse.jgit.internal.storage.reftable.RefCursor;
import org.eclipse.jgit.internal.storage.reftable.ReftableReader;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.Ref;
@ -74,7 +78,8 @@ class BenchmarkReftable extends TextBuiltin {
enum Test {
SCAN,
SEEK_COLD, SEEK_HOT,
BY_ID_COLD, BY_ID_HOT;
BY_ID_COLD, BY_ID_HOT,
WRITE_STACK,
}
@Option(name = "--tries")
@ -116,6 +121,9 @@ protected void run() throws Exception {
case BY_ID_HOT:
byIdHot(ObjectId.fromString(objectId));
break;
case WRITE_STACK:
writeStack();
break;
}
}
@ -123,6 +131,33 @@ private void printf(String fmt, Object... args) throws IOException {
errw.println(String.format(fmt, args));
}
@SuppressWarnings({ "nls", "boxing" })
private void writeStack() throws Exception {
File dir = new File(reftablePath);
File stackFile = new File(reftablePath + ".stack");
dir.mkdirs();
long start = System.currentTimeMillis();
try (FileReftableStack stack = new FileReftableStack(stackFile, dir,
null, () -> new Config())) {
List<Ref> refs = readLsRemote().asList();
for (Ref r : refs) {
final long j = stack.getMergedReftable().maxUpdateIndex() + 1;
if (!stack.addReftable(w -> {
w.setMaxUpdateIndex(j).setMinUpdateIndex(j).begin()
.writeRef(r);
})) {
throw new IOException("should succeed");
}
}
long dt = System.currentTimeMillis() - start;
printf("%12s %10d ms avg %6d us/write", "reftable", dt,
(dt * 1000) / refs.size());
}
}
@SuppressWarnings({ "nls", "boxing" })
private void scan() throws Exception {
long start, tot;