zyxxoo commented on code in PR #2262:
URL:
https://github.com/apache/incubator-hugegraph/pull/2262#discussion_r1290881610
##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java:
##########
@@ -186,8 +185,56 @@ public static boolean checkAndParseAction(String action) {
} else if (action.equals(ACTION_ELIMINATE)) {
return false;
} else {
- throw new NotSupportedException(
- String.format("Not support action '%s'", action));
+ throw new NotSupportedException(String.format("Not support action
'%s'", action));
+ }
+ }
+
+ public static class ApiMeasurer {
+
+ public static final String EDGE_ITER = "edge_iterations";
+ public static final String VERTICE_ITER = "vertice_iterations";
+ public static final String COST = "cost";
+ private final long timeStart;
+ private final Map<String, Object> measures;
+
+ public ApiMeasurer() {
+ this.timeStart = System.currentTimeMillis();
+ this.measures = InsertionOrderUtil.newMap();
+ }
+
+ public Map<String, Object> measures() {
+ measures.put(COST, System.currentTimeMillis() - timeStart);
Review Comment:
compute duration use System.nanoTime perfered
##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java:
##########
@@ -186,8 +185,56 @@ public static boolean checkAndParseAction(String action) {
} else if (action.equals(ACTION_ELIMINATE)) {
return false;
} else {
- throw new NotSupportedException(
- String.format("Not support action '%s'", action));
+ throw new NotSupportedException(String.format("Not support action
'%s'", action));
+ }
+ }
+
+ public static class ApiMeasurer {
+
+ public static final String EDGE_ITER = "edge_iterations";
+ public static final String VERTICE_ITER = "vertice_iterations";
+ public static final String COST = "cost";
+ private final long timeStart;
+ private final Map<String, Object> measures;
+
+ public ApiMeasurer() {
+ this.timeStart = System.currentTimeMillis();
+ this.measures = InsertionOrderUtil.newMap();
+ }
+
+ public Map<String, Object> measures() {
+ measures.put(COST, System.currentTimeMillis() - timeStart);
+ return measures;
+ }
+
+ public void put(String key, String value) {
+ this.measures.put(key, value);
+ }
+
+ public void put(String key, long value) {
+ this.measures.put(key, value);
+ }
+
+ public void put(String key, int value) {
+ this.measures.put(key, value);
+ }
+
+ protected void addCount(String key, long value) {
+ Object current = measures.get(key);
+ if (current == null) {
+ measures.put(key, new MutableLong(value));
+ } else if (current instanceof MutableLong) {
+ MutableLong currentMutableLong = (MutableLong) current;
+ currentMutableLong.add(value);
+ } else if (current instanceof Long) {
Review Comment:
measures.computeIfAbsent(key, MutableLong.new).add(value)
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -82,13 +82,16 @@ public class HugeTraverser {
public static final String DEFAULT_SAMPLE = "100";
public static final String DEFAULT_WEIGHT = "0";
public static final int DEFAULT_MAX_DEPTH = 5000;
-
- protected static final int MAX_VERTICES = 10;
-
// Empirical value of scan limit, with which results can be returned in 3s
public static final String DEFAULT_PAGE_LIMIT = "100000";
-
public static final long NO_LIMIT = -1L;
+ protected static final Logger LOG = Log.logger(HugeTraverser.class);
+ protected static final int MAX_VERTICES = 10;
+ private static CollectionFactory collectionFactory;
+ private final HugeGraph graph;
+ // for apimeasure
+ public AtomicLong edgeIterCounter = new AtomicLong(0);
Review Comment:
Wouldn't it be better for this class to have no side effects?
--
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]