Last active
August 6, 2021 14:35
-
-
Save porunov/9b0c10ec0c06c1ba32695897db9b2412 to your computer and use it in GitHub Desktop.
JanusGraph simple benchmark with disabled CQL executor service
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
// Copyright 2021 JanusGraph Authors | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
// See the License for the specific language governing permissions and | |
// limitations under the License. | |
package org.janusgraph.graphdb.cql; | |
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; | |
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; | |
import org.apache.tinkerpop.gremlin.structure.Direction; | |
import org.apache.tinkerpop.gremlin.structure.Edge; | |
import org.apache.tinkerpop.gremlin.structure.Vertex; | |
import org.janusgraph.JanusGraphCassandraContainer; | |
import org.janusgraph.core.JanusGraph; | |
import org.janusgraph.core.JanusGraphFactory; | |
import org.janusgraph.core.PropertyKey; | |
import org.janusgraph.core.schema.JanusGraphManagement; | |
import org.janusgraph.diskstorage.configuration.WriteConfiguration; | |
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.Iterator; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import static org.janusgraph.diskstorage.cql.CQLConfigOptions.ATOMIC_BATCH_MUTATE; | |
import static org.janusgraph.diskstorage.cql.CQLConfigOptions.BATCH_STATEMENT_SIZE; | |
import static org.janusgraph.diskstorage.cql.CQLConfigOptions.EXECUTOR_SERVICE_ENABLED; | |
import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ASSIGN_TIMESTAMP; | |
/* Required dependency: | |
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-generator-annprocess --> | |
<dependency> | |
<groupId>org.openjdk.jmh</groupId> | |
<artifactId>jmh-generator-annprocess</artifactId> | |
<version>1.32</version> | |
<scope>test</scope> | |
</dependency> | |
*/ | |
@BenchmarkMode(Mode.AverageTime) | |
@Fork(1) | |
@State(Scope.Benchmark) | |
@OutputTimeUnit(TimeUnit.MILLISECONDS) | |
public class TraverseBenchmark { | |
static final JanusGraphCassandraContainer cqlContainer = new JanusGraphCassandraContainer(); | |
static { | |
cqlContainer.start(); | |
} | |
private static final AtomicInteger RUN_COUNT = new AtomicInteger(0); | |
@Param({ "true", "false" }) | |
Boolean assignTimestamp; | |
@Param({ "true", "false" }) | |
Boolean atomicBatch; | |
@Param({ "20", "1" }) | |
Integer batchSize; | |
JanusGraph graph; | |
GraphTraversalSource g; | |
public WriteConfiguration getConfiguration() { | |
return cqlContainer.getConfiguration(getClass().getSimpleName()+RUN_COUNT.incrementAndGet()).getConfiguration(); | |
} | |
@Setup | |
public void setup() { | |
WriteConfiguration configuration = getConfiguration(); | |
configuration.set(ASSIGN_TIMESTAMP.toStringWithoutRoot(), assignTimestamp); | |
configuration.set(ATOMIC_BATCH_MUTATE.toStringWithoutRoot(), atomicBatch); | |
configuration.set(BATCH_STATEMENT_SIZE.toStringWithoutRoot(), batchSize); | |
configuration.set(EXECUTOR_SERVICE_ENABLED.toStringWithoutRoot(), false); | |
graph = JanusGraphFactory.open(configuration); | |
JanusGraphManagement mgmt = graph.openManagement(); | |
if(!mgmt.containsEdgeLabel("connection")){ | |
PropertyKey nameKey = mgmt.makePropertyKey("name").dataType(String.class).make(); | |
mgmt.makeEdgeLabel("connection").make(); | |
mgmt.buildIndex("name", Vertex.class).addKey(nameKey).buildCompositeIndex(); | |
mgmt.commit(); | |
GraphTraversalSource g = graph.traversal(); | |
for (int i = 0; i < 3000;) { | |
Vertex a = g.addV().property("name", "value" + i++).next(); | |
Vertex b = g.addV().property("name", "value" + i++).next(); | |
a.addEdge("connection", b, "name", "value "+i++); | |
} | |
for (int i = 0; i < 100000; i++) { | |
g.addV().iterate(); | |
} | |
graph.tx().commit(); | |
} | |
g = graph.traversal(); | |
} | |
@TearDown | |
public void tearDown() { | |
graph.close(); | |
} | |
@Benchmark | |
public void testTraversingTime(){ | |
GraphTraversal<Vertex, Vertex> graphTraversal = g.V(); | |
while (graphTraversal.hasNext()){ | |
Vertex vertex = graphTraversal.next(); | |
Iterator propertiesIt = vertex.properties(); | |
while (propertiesIt.hasNext()){ | |
propertiesIt.next(); | |
} | |
Iterator<Edge> edgesIt = vertex.edges(Direction.BOTH); | |
while (edgesIt.hasNext()){ | |
Edge edge = edgesIt.next(); | |
propertiesIt = edge.properties(); | |
while (propertiesIt.hasNext()){ | |
propertiesIt.next(); | |
} | |
} | |
} | |
g.tx().rollback(); | |
} | |
public static void main(String[] args) throws RunnerException { | |
Options options = new OptionsBuilder() | |
.include(TraverseBenchmark.class.getSimpleName()) | |
.warmupIterations(1) | |
.measurementIterations(1) | |
.build(); | |
new Runner(options).run(); | |
cqlContainer.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment