Browse Source

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
next
Han-Wen Nienhuys 5 years ago committed by Matthias Sohn
parent
commit
0356613f48
  1. 37
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java

37
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java

@ -51,14 +51,18 @@ import static org.eclipse.jgit.lib.Ref.Storage.NEW;
import static org.eclipse.jgit.lib.Ref.Storage.PACKED; import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; 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.io.BlockSource;
import org.eclipse.jgit.internal.storage.reftable.RefCursor; import org.eclipse.jgit.internal.storage.reftable.RefCursor;
import org.eclipse.jgit.internal.storage.reftable.ReftableReader; 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.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
@ -74,7 +78,8 @@ class BenchmarkReftable extends TextBuiltin {
enum Test { enum Test {
SCAN, SCAN,
SEEK_COLD, SEEK_HOT, SEEK_COLD, SEEK_HOT,
BY_ID_COLD, BY_ID_HOT; BY_ID_COLD, BY_ID_HOT,
WRITE_STACK,
} }
@Option(name = "--tries") @Option(name = "--tries")
@ -116,6 +121,9 @@ class BenchmarkReftable extends TextBuiltin {
case BY_ID_HOT: case BY_ID_HOT:
byIdHot(ObjectId.fromString(objectId)); byIdHot(ObjectId.fromString(objectId));
break; break;
case WRITE_STACK:
writeStack();
break;
} }
} }
@ -123,6 +131,33 @@ class BenchmarkReftable extends TextBuiltin {
errw.println(String.format(fmt, args)); 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" }) @SuppressWarnings({ "nls", "boxing" })
private void scan() throws Exception { private void scan() throws Exception {
long start, tot; long start, tot;

Loading…
Cancel
Save