DanGuge commented on code in PR #2262:
URL:
https://github.com/apache/incubator-hugegraph/pull/2262#discussion_r1278759670
##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java:
##########
@@ -190,4 +192,42 @@ public static boolean checkAndParseAction(String action) {
String.format("Not support action '%s'", action));
}
}
+
+ public static class ApiMeasure {
+ public static final String EDGE_ITER = "edge_iters";
+ public static final String VERTICE_ITER = "vertice_iters";
+ public static final String COST = "cost";
+ protected long timeStart = System.currentTimeMillis();
+ protected HashMap<String, Object> mapResult = new LinkedHashMap<>();
+
+ public Map<String, Object> getResult() {
+ mapResult.put(COST, System.currentTimeMillis() - timeStart);
+ return mapResult;
+ }
+
+ public void put(String key, String value) {
+ this.mapResult.put(key, value);
+ }
+
+ public void put(String key, long value) {
+ this.mapResult.put(key, value);
+ }
+
+ public void put(String key, int value) {
+ this.mapResult.put(key, value);
+ }
+
+ protected void addCount(String key, long value) {
+ long cur = 0;
+ if (this.mapResult.containsKey(key)) {
+ cur = (long) this.mapResult.get(key);
+ }
+ this.mapResult.put(key, cur + value);
Review Comment:
fixed
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CollectionPathsTraverser.java:
##########
@@ -274,4 +280,26 @@ protected int accessedNodes() {
return this.sourcesAll.size() + this.targetsAll.size();
}
}
+
+ public static class WrappedPathCollection {
Review Comment:
fixed
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/MultiNodeShortestPathTraverser.java:
##########
@@ -56,70 +83,69 @@ public List<Path> multiNodeShortestPath(Iterator<Vertex>
vertices,
});
if (maxDepth >= this.concurrentDepth() && vertexCount > 10) {
- return this.multiNodeShortestPathConcurrent(pairs, step,
- maxDepth, capacity);
+ return this.multiNodeShortestPathConcurrent(pairs, step, maxDepth,
capacity);
} else {
- return this.multiNodeShortestPathSingle(pairs, step,
- maxDepth, capacity);
+ return this.multiNodeShortestPathSingle(pairs, step, maxDepth,
capacity);
}
}
- public List<Path> multiNodeShortestPathConcurrent(List<Pair<Id, Id>> pairs,
- EdgeStep step,
- int maxDepth,
- long capacity) {
- List<Path> results = new CopyOnWriteArrayList<>();
+ public WrappedListPath multiNodeShortestPathConcurrent(List<Pair<Id, Id>>
pairs,
+ EdgeStep step, int
maxDepth,
+ long capacity) {
+ List<Path> paths = new CopyOnWriteArrayList<>();
+ Set<Edge> edges = new CopyOnWriteArraySet<>();
ShortestPathTraverser traverser =
- new ShortestPathTraverser(this.graph());
+ new ShortestPathTraverser(this.graph());
this.traversePairs(pairs.iterator(), pair -> {
Path path = traverser.shortestPath(pair.getLeft(), pair.getRight(),
step, maxDepth, capacity);
if (!Path.EMPTY.equals(path)) {
- results.add(path);
+ paths.add(path);
}
+ edges.addAll(path.getEdges());
});
+ this.vertexIterCounter.addAndGet(traverser.vertexIterCounter.get());
+ this.edgeIterCounter.addAndGet(traverser.edgeIterCounter.get());
- return results;
+ return new WrappedListPath(paths, edges);
}
- public List<Path> multiNodeShortestPathSingle(List<Pair<Id, Id>> pairs,
- EdgeStep step, int maxDepth,
- long capacity) {
- List<Path> results = newList();
+ public WrappedListPath multiNodeShortestPathSingle(List<Pair<Id, Id>>
pairs,
+ EdgeStep step, int
maxDepth,
+ long capacity) {
+ List<Path> paths = newList();
+ Set<Edge> edges = newSet();
ShortestPathTraverser traverser =
- new ShortestPathTraverser(this.graph());
+ new ShortestPathTraverser(this.graph());
for (Pair<Id, Id> pair : pairs) {
Path path = traverser.shortestPath(pair.getLeft(), pair.getRight(),
step, maxDepth, capacity);
if (!Path.EMPTY.equals(path)) {
- results.add(path);
+ paths.add(path);
}
+ edges.addAll(path.getEdges());
}
- return results;
+ this.vertexIterCounter.addAndGet(traverser.vertexIterCounter.get());
+ this.edgeIterCounter.addAndGet(traverser.edgeIterCounter.get());
+
+ return new WrappedListPath(paths, edges);
}
- private static <T> void cmn(List<T> all, int m, int n, int current,
- List<T> result, Consumer<List<T>> consumer) {
- assert m <= all.size();
- assert current <= all.size();
- if (result == null) {
- result = newList(n);
- }
- if (n == 0) {
- // All n items are selected
- consumer.accept(result);
- return;
+ public static class WrappedListPath {
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]