Created
June 8, 2021 16:29
-
-
Save li-boxuan/996799939c55faf42fc07db7abd4385d to your computer and use it in GitHub Desktop.
JanusGraph simple MultiQueryBenchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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