forked from JanusGraph/janusgraph
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable multiQuery optimization for PropertyMapStep and ElementMapStep…
… [cql-tests] [tp-tests] Adds possibility to fetch properties and labels of vertices using valueMap, elementMap, propertyMap steps. Adds fetching modes to properties, values, valueMap, elementMap, propertyMap steps to be able to preFetch all properties (single slice query) or only required properties (separate slice query per each requested property). Fixes JanusGraph#2444 Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
- Loading branch information
Showing
18 changed files
with
1,479 additions
and
72 deletions.
There are no files selected for viewing
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
462 changes: 453 additions & 9 deletions
462
janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/JanusGraphTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
230 changes: 230 additions & 0 deletions
230
janusgraph-benchmark/src/main/java/org/janusgraph/CQLMultiQueryPropertiesBenchmark.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
// Copyright 2023 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; | ||
|
||
import org.apache.tinkerpop.gremlin.process.traversal.step.util.WithOptions; | ||
import org.apache.tinkerpop.gremlin.structure.Vertex; | ||
import org.janusgraph.core.JanusGraph; | ||
import org.janusgraph.core.JanusGraphFactory; | ||
import org.janusgraph.core.JanusGraphTransaction; | ||
import org.janusgraph.core.schema.JanusGraphManagement; | ||
import org.janusgraph.diskstorage.BackendException; | ||
import org.janusgraph.diskstorage.configuration.ModifiableConfiguration; | ||
import org.janusgraph.diskstorage.configuration.WriteConfiguration; | ||
import org.janusgraph.diskstorage.cql.CQLConfigOptions; | ||
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 java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode(Mode.AverageTime) | ||
@Fork(1) | ||
@State(Scope.Benchmark) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
public class CQLMultiQueryPropertiesBenchmark { | ||
@Param({"100", "5000", "50000"}) | ||
int verticesAmount; | ||
|
||
@Param({"true", "false"}) | ||
boolean fastProperty; | ||
|
||
@Param({ | ||
"all_properties", | ||
"required_properties_only", | ||
"none"}) | ||
String propertiesBatchMode; | ||
|
||
JanusGraph graph; | ||
|
||
public WriteConfiguration getConfiguration() { | ||
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration(); | ||
config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"cql"); | ||
config.set(CQLConfigOptions.LOCAL_DATACENTER, "dc1"); | ||
config.set(GraphDatabaseConfiguration.USE_MULTIQUERY, true); | ||
config.set(GraphDatabaseConfiguration.PROPERTIES_BATCH_MODE, propertiesBatchMode); | ||
config.set(GraphDatabaseConfiguration.PROPERTY_PREFETCHING, fastProperty); | ||
return config.getConfiguration(); | ||
} | ||
|
||
@Setup | ||
public void setUp() throws Exception { | ||
graph = JanusGraphFactory.open(getConfiguration()); | ||
int propertiesAmount = 10; | ||
|
||
JanusGraphManagement mgmt = graph.openManagement(); | ||
for(int i=0;i<propertiesAmount;i++){ | ||
mgmt.makePropertyKey("prop"+i).dataType(String.class).make(); | ||
} | ||
mgmt.commit(); | ||
|
||
for (int i = 0; i < verticesAmount; i++) { | ||
Vertex vertex = graph.addVertex(); | ||
for(int j=0;j<propertiesAmount;j++){ | ||
vertex.property("prop"+j, | ||
"SomeTestPropertyValue "+j+" 0123456789 ABCDEFG"); | ||
} | ||
} | ||
|
||
graph.tx().commit(); | ||
} | ||
|
||
@TearDown | ||
public void tearDown() throws BackendException { | ||
JanusGraphFactory.drop(graph); | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getValueMap() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<Map<Object, Object>> result = tx.traversal().V().valueMap() | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getValueMapWithOptions() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<Map<Object, Object>> result = tx.traversal().V().valueMap().with(WithOptions.tokens, WithOptions.all) | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getValueMapWithOptionsLimitedOne() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<Map<Object, Object>> result = tx.traversal().V().valueMap().with(WithOptions.tokens, WithOptions.all) | ||
.limit(1) | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getValueMapWithOptionsLimitedBatchSizePlusOne() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<Map<Object, Object>> result = tx.traversal().V().valueMap().with(WithOptions.tokens, WithOptions.all) | ||
.limit(GraphDatabaseConfiguration.LIMITED_BATCH_SIZE.getDefaultValue()+1) | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getPropertyMap() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().propertyMap() | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getElementMap() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().elementMap() | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getValues() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().values() | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getProperties() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().properties() | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getValueMapSingleProperty() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().valueMap("prop1") | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getPropertyMapSingleProperty() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().propertyMap("prop1") | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getElementMapSingleProperty() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().elementMap("prop1") | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getValuesSingleProperty() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().values("prop1") | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
|
||
@Benchmark | ||
public List<? extends Object> getPropertiesSingleProperty() { | ||
JanusGraphTransaction tx = graph.buildTransaction() | ||
.start(); | ||
List<? extends Object> result = tx.traversal().V().properties("prop1") | ||
.toList(); | ||
tx.rollback(); | ||
return result; | ||
} | ||
} |
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
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
Oops, something went wrong.