Skip to content

Instantly share code, notes, and snippets.

@li-boxuan
Created June 8, 2021 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li-boxuan/996799939c55faf42fc07db7abd4385d to your computer and use it in GitHub Desktop.
Save li-boxuan/996799939c55faf42fc07db7abd4385d to your computer and use it in GitHub Desktop.
JanusGraph simple MultiQueryBenchmark
package org.janusgraph.graphdb.query;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.Cardinality;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraphTransaction;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.janusgraph.diskstorage.configuration.ModifiableConfiguration;
import org.janusgraph.diskstorage.configuration.WriteConfiguration;
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.List;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@State(Scope.Benchmark)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class MultiQueryBenchmark {
@Param({"100", "1000", "3000"})
int fanoutFactor;
JanusGraph graph;
public WriteConfiguration getConfiguration() {
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
return config.getConfiguration();
}
@Setup
public void setUp() throws Exception {
graph = JanusGraphFactory.open(getConfiguration());
JanusGraphManagement mgmt = graph.openManagement();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
mgmt.buildIndex("nameIndex", Vertex.class).addKey(name).buildCompositeIndex();
mgmt.commit();
Vertex v = graph.addVertex("name", "outer");
for (int i = 0; i < fanoutFactor; i++) {
Vertex otherV = graph.addVertex("name", "middle");
v.addEdge("connects", otherV);
for (int j = 0; j < fanoutFactor; j++) {
Vertex innerV = graph.addVertex("name", "inner");
otherV.addEdge("connects", innerV);
}
graph.tx().commit();
}
}
@TearDown
public void tearDown() {
graph.close();
}
@Benchmark
public List<Object> getNeighborNames() {
JanusGraphTransaction tx = graph.buildTransaction()
.start();
List<Object> names = tx.traversal().V().has("name", "outer").out().out().limit(1).values("name").toList();
tx.rollback();
return names;
}
public static void main(String[] args) throws RunnerException {
Options options = new OptionsBuilder()
.include(MultiQueryBenchmark.class.getSimpleName())
.warmupIterations(10)
.measurementIterations(10)
.build();
new Runner(options).run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment