You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/10/09 17:50:27 UTC

[10/30] incubator-tinkerpop git commit: tweaks to make GroupStep faster w/ respective benchmark validation in TinkerGraphPlayTest.

tweaks to make GroupStep faster w/ respective benchmark validation in TinkerGraphPlayTest.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/cb7fc5bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/cb7fc5bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/cb7fc5bc

Branch: refs/heads/TINKERPOP3-876
Commit: cb7fc5bc481cb83599a7a02e630ea40b498db5ee
Parents: 12c70d5
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Oct 8 13:26:45 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Oct 8 13:26:45 2015 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/GroupStep.java   | 13 +++++++----
 .../structure/TinkerGraphPlayTest.java          | 24 +++++++++++++++-----
 2 files changed, 26 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cb7fc5bc/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java
index 3442474..729747d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java
@@ -26,9 +26,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
 import org.apache.tinkerpop.gremlin.process.traversal.step.MapReducer;
 import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
-import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.GroupStepHelper;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep;
@@ -149,7 +149,7 @@ public final class GroupStep<S, K, V> extends ReducingBarrierStep<S, Map<K, V>>
     private static class GroupBiFunction<S, K, V> implements BiFunction<Map<K, Traversal.Admin<S, V>>, Traverser.Admin<S>, Map<K, Traversal.Admin<S, V>>>, Serializable {
 
         private final GroupStep<S, K, V> groupStep;
-        private int counter = 0;
+        private Map<K, Integer> counters = new HashMap<>();
 
         private GroupBiFunction(final GroupStep<S, K, V> groupStep) {
             this.groupStep = groupStep;
@@ -161,12 +161,15 @@ public final class GroupStep<S, K, V> extends ReducingBarrierStep<S, Map<K, V>>
             Traversal.Admin<S, V> traversal = mutatingSeed.get(key);
             if (null == traversal) {
                 traversal = this.groupStep.valueReduceTraversal.clone();
+                this.counters.put(key, 0);
                 mutatingSeed.put(key, traversal);
             }
+
             traversal.addStart(traverser);
-            if (++this.counter > 7500) {
-                this.counter = 0;
-                mutatingSeed.values().forEach(t -> TraversalHelper.getFirstStepOfAssignableClass(Barrier.class, t).ifPresent(Barrier::processAllStarts));
+            int count = this.counters.compute(key, (k,i) -> ++i);
+            if (count > 10000) {
+                this.counters.put(key,0);
+                TraversalHelper.getFirstStepOfAssignableClass(Barrier.class, traversal).ifPresent(Barrier::processAllStarts);
             }
             return mutatingSeed;
         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cb7fc5bc/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index af39b54..e8f58bb 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -53,18 +53,30 @@ public class TinkerGraphPlayTest {
         graph.io(GraphMLIo.build()).readGraph("data/grateful-dead.xml");
         /////////
 
-        System.out.println("groupV3d0: " + g.V().both("followedBy").groupV3d0().by("songType").by("performances").by(__.sum(Scope.local)).next());
-        System.out.println("group: " + g.V().both("followedBy").group().by("songType").by(__.values("performances").sum()).next() + "\n\n");
+        System.out.println("groupV3d0: " + g.V().both("followedBy").both("followedBy").groupV3d0().by("songType").by().by(__.count(Scope.local)).next());
+        System.out.println("group: " + g.V().both("followedBy").both("followedBy").group().by("songType").by(count()).next());
 
+        //
+        System.out.println("\n\nBig Values -- by(songType)");
 
-        System.out.println("group: " + TimeUtil.clock(1000, () -> g.V().both("followedBy").group().by("songType").by(__.values("performances").sum()).next()));
-        System.out.println("groupV3d0: " + TimeUtil.clock(1000, () -> g.V().both("followedBy").groupV3d0().by("songType").by("performances").by(__.sum(Scope.local)).next()));
+        System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("songType").by(count()).next()));
+        System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("songType").by().by(__.count(Scope.local)).next()) + "\n");
 
         ///
 
-        System.out.println("group: " + TimeUtil.clock(1000, () -> g.V().both("followedBy").group().by("songType").by("performances").next()));
-        System.out.println("groupV3d0: " + TimeUtil.clock(1000, () -> g.V().both("followedBy").groupV3d0().by("songType").by("performances").next()));
+        System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("songType").by(fold()).next()));
+        System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("songType").by().next()));
 
+        ///
+        System.out.println("\n\nBig Keys -- by(name)");
+
+        System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("name").by(count()).next()));
+        System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("name").by().by(__.count(Scope.local)).next()) + "\n");
+
+        ///
+
+        System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("name").by(fold()).next()));
+        System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("name").by().next()));
 
     }