You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/03/15 16:36:30 UTC

[01/20] tinkerpop git commit: TINKERPOP-1644 Updated changelog

Repository: tinkerpop
Updated Branches:
  refs/heads/master b5bd36bf5 -> ef10d8f2b


TINKERPOP-1644 Updated changelog


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

Branch: refs/heads/master
Commit: b29ba12109e7e88bc3465d08f6177e5ded17ca59
Parents: 4bdeac4
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 16:15:27 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b29ba121/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 24e5e9c..9c3313e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Moved the `caffeine` dependency down to `gremlin-groovy` and out of `gremlin-server`.
 * Script compilation is synchronised.
 * Script compilation times are placed in to logs.
 * Failed scripts will not be recompiled.


[04/20] tinkerpop git commit: TINKERPOP-1644 Remove gremlin-server caffeine dependency

Posted by sp...@apache.org.
TINKERPOP-1644 Remove gremlin-server caffeine dependency

Caffeine is now down in gremlin-groovy.


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

Branch: refs/heads/master
Commit: 608f024f7bb83eb168a6aa637d46ee0650674903
Parents: 1df71c8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 13:31:52 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 gremlin-server/pom.xml | 5 -----
 1 file changed, 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/608f024f/gremlin-server/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-server/pom.xml b/gremlin-server/pom.xml
index adb41fd..7a4cad9 100644
--- a/gremlin-server/pom.xml
+++ b/gremlin-server/pom.xml
@@ -55,11 +55,6 @@ limitations under the License.
             <artifactId>log4j</artifactId>
             <optional>true</optional>
         </dependency>
-        <dependency>
-            <groupId>com.github.ben-manes.caffeine</groupId>
-            <artifactId>caffeine</artifactId>
-            <version>2.3.1</version>
-        </dependency>
         <!-- METRICS -->
         <dependency>
             <groupId>com.codahale.metrics</groupId>


[05/20] tinkerpop git commit: TINKERPOP-1644 Use future instead of maintaining a separate map of failures.

Posted by sp...@apache.org.
TINKERPOP-1644
Use future instead of maintaining a separate map of failures.


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

Branch: refs/heads/master
Commit: deb68280d986b086120d56a73659b1869c07a475
Parents: 13c93ca
Author: BrynCooke <br...@gmail.com>
Authored: Tue Mar 7 16:54:58 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 .../jsr223/GremlinGroovyScriptEngine.java       | 69 ++++++++------------
 1 file changed, 26 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/deb68280/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index a8365a2..67275f8 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -79,6 +79,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -155,8 +157,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     /**
      * Script to generated Class map.
      */
-    private ManagedConcurrentValueMap<String, Class> classMap = new ManagedConcurrentValueMap<>(ReferenceBundle.getSoftBundle());
-    private ManagedConcurrentValueMap<String, CompilationFailedException> failedClassMap = new ManagedConcurrentValueMap<>(ReferenceBundle.getSoftBundle());
+    private ManagedConcurrentValueMap<String, Future<Class>> classMap = new ManagedConcurrentValueMap<>(ReferenceBundle.getSoftBundle());
 
     /**
      * Global closures map - this is used to simulate a single global functions namespace
@@ -533,56 +534,38 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         return makeInterface(thiz, clazz);
     }
 
-    private Class getScriptClassFromMap(String script) throws CompilationFailedException {
-        CompilationFailedException exception = failedClassMap.get(script);
-        if(exception != null) {
-            throw exception;
-        }
-        return classMap.get(script);
-
-    }
-
     Class getScriptClass(final String script) throws CompilationFailedException {
-        Class clazz = getScriptClassFromMap(script);
-        if (clazz != null) {
-            return clazz;
-        }
-        synchronized (this) {
-            clazz = getScriptClassFromMap(script);
+        Future<Class> clazz = classMap.get(script);
+
+        long start = System.currentTimeMillis();
+        try {
             if (clazz != null) {
-                return clazz;
+                return clazz.get();
             }
 
-            long start = System.currentTimeMillis();
-            try {
-                clazz = loader.parseClass(script, generateScriptName());
-                long time = System.currentTimeMillis() - start;
-                if(time > 5000) {
-                    //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
-                    //Scripts with a large numbers of parameters often trigger this and should be avoided.
-                    log.warn("Script compilation {} took {}ms", script, time);
-                }
-                else {
-                    log.debug("Script compilation {} took {}ms", script, time);
-                }
-
+            clazz = CompletableFuture.supplyAsync(() -> loader.parseClass(script, generateScriptName()));
+            classMap.put(script, clazz);
+            return clazz.get();
 
-            }
-            catch(CompilationFailedException t) {
+        } catch (Exception e) {
+            if (e.getCause() instanceof CompilationFailedException) {
                 long finish = System.currentTimeMillis();
-                log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, t);
-                failedClassMap.put(script, t);
-                throw t;
+                log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e.getCause());
+                throw (CompilationFailedException) e.getCause();
+            } else {
+                throw new AssertionError("Unexpected exception when compiling script", e);
             }
-            catch(Throwable t) {
-                long finish = System.currentTimeMillis();
-                log.error("Script compilation FAILED with throwable {} took {}ms {}", script, finish - start, t);
-                throw t;
+        } finally {
+            long time = System.currentTimeMillis() - start;
+            if (time > 5000) {
+                //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
+                //Scripts with a large numbers of parameters often trigger this and should be avoided.
+                log.warn("Script compilation {} took {}ms", script, time);
+            } else {
+                log.debug("Script compilation {} took {}ms", script, time);
             }
-            classMap.put(script, clazz);
-
-            return clazz;
         }
+
     }
 
     boolean isCached(final String script) {


[12/20] tinkerpop git commit: TINKERPOP-1644 Added metrics to GremlinGroovyScriptEngine

Posted by sp...@apache.org.
TINKERPOP-1644 Added metrics to GremlinGroovyScriptEngine


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

Branch: refs/heads/master
Commit: 8ffa5af6ff56933c1955e88e8aa42c06cb69162b
Parents: a06072b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 10:30:17 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:13:03 2017 -0500

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   2 +
 .../jsr223/GremlinGroovyScriptEngine.java       | 122 ++++++++++++++++++-
 ...roovyScriptEngineCompilationOptionsTest.java |   8 +-
 .../jsr223/GremlinGroovyScriptEngineTest.java   |  70 ++++++++++-
 4 files changed, 193 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ffa5af6/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 9c3313e..3729271 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,7 +26,9 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Added various metrics to the `GremlinGroovyScriptEngine` around script compilation.
 * Moved the `caffeine` dependency down to `gremlin-groovy` and out of `gremlin-server`.
+* Improved script compilation in `GremlinGroovyScriptEngine to use better caching, log long compile times and prevent failed compilations from recompiling on future requests.
 * Script compilation is synchronised.
 * Script compilation times are placed in to logs.
 * Failed scripts will not be recompiled.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ffa5af6/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 3bcb06c..0ed8d84 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -164,7 +164,10 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     /**
      * Script to generated Class map.
      */
-    private final LoadingCache<String, Future<Class>> classMap = Caffeine.newBuilder().softValues().build(new CacheLoader<String, Future<Class>>() {
+    private final LoadingCache<String, Future<Class>> classMap = Caffeine.newBuilder().
+            softValues().
+            recordStats().
+            build(new CacheLoader<String, Future<Class>>() {
         @Override
         public Future<Class> load(final String script) throws Exception {
             final long start = System.currentTimeMillis();
@@ -175,6 +178,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
                 } catch (CompilationFailedException e) {
                     final long finish = System.currentTimeMillis();
                     log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e);
+                    failedCompilationCount.incrementAndGet();
                     throw e;
                 } finally {
                     final long time = System.currentTimeMillis() - start;
@@ -208,6 +212,13 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     private final AtomicLong longRunCompilationCount = new AtomicLong(0L);
 
     /**
+     * A counter for the instance that tracks the number of failed compilations. Note that the failures need to be
+     * tracked outside of cache failure load stats because the loading mechanism will always successfully return
+     * a future and won't trigger a failure.
+     */
+    private final AtomicLong failedCompilationCount = new AtomicLong(0L);
+
+    /**
      * The list of loaded plugins for the console.
      */
     private final Set<String> loadedPlugins = new HashSet<>();
@@ -589,10 +600,117 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     /**
      * Gets the number of compilations that extended beyond the {@link #expectedCompilationTime}.
      */
-    public long getLongRunCompilationCount() {
+    public long getClassCacheLongRunCompilationCount() {
         return longRunCompilationCount.longValue();
     }
 
+    /**
+     * Gets the estimated size of the class cache for compiled scripts.
+     */
+    public long getClassCacheEstimatedSize() {
+        return classMap.estimatedSize();
+    }
+
+    /**
+     * Gets the average time spent compiling new scripts.
+     */
+    public double getClassCacheAverageLoadPenalty() {
+        return classMap.stats().averageLoadPenalty();
+    }
+
+    /**
+     * Gets the number of times a script compiled to a class has been evicted from the cache.
+     */
+    public long getClassCacheEvictionCount() {
+        return classMap.stats().evictionCount();
+    }
+
+    /**
+     * Gets the sum of the weights of evicted entries from the class cache.
+     */
+    public long getClassCacheEvictionWeight() {
+        return classMap.stats().evictionWeight();
+    }
+
+    /**
+     * Gets the number of times cache look up for a compiled script returned a cached value.
+     */
+    public long getClassCacheHitCount() {
+        return classMap.stats().hitCount();
+    }
+
+    /**
+     * Gets the hit rate of the class cache.
+     */
+    public double getClassCacheHitRate() {
+        return classMap.stats().hitRate();
+    }
+
+    /**
+     * Gets the total number of times the cache lookup method attempted to compile new scripts.
+     */
+    public long getClassCacheLoadCount() {
+        return classMap.stats().loadCount();
+    }
+
+    /**
+     * Gets the total number of times the cache lookup method failed to compile a new script.
+     */
+    public long getClassCacheLoadFailureCount() {
+        // don't use classMap.stats().loadFailureCount() because the load mechanism always succeeds with a future
+        // that will in turn contain the success or failure
+        return failedCompilationCount.longValue();
+    }
+
+    /**
+     * Gets the ratio of script compilation attempts that failed.
+     */
+    public double getClassCacheLoadFailureRate() {
+        // don't use classMap.stats().loadFailureRate() because the load mechanism always succeeds with a future
+        // that will in turn contain the success or failure
+        long totalLoadCount = classMap.stats().loadCount();
+        return (totalLoadCount == 0)
+                ? 0.0
+                : (double) failedCompilationCount.longValue() / totalLoadCount;
+    }
+
+    /**
+     * Gets the total number of times the cache lookup method succeeded to compile a new script.
+     */
+    public long getClassCacheLoadSuccessCount() {
+        // don't use classMap.stats().loadSuccessCount() because the load mechanism always succeeds with a future
+        // that will in turn contain the success or failure
+        return classMap.stats().loadCount() - failedCompilationCount.longValue();
+    }
+
+    /**
+     * Gets the total number of times the cache lookup method returned a newly compiled script.
+     */
+    public long getClassCacheMissCount() {
+        return classMap.stats().missCount();
+    }
+
+    /**
+     * Gets the ratio of script compilation attempts that were misses.
+     */
+    public double getClassCacheMissRate() {
+        return classMap.stats().missRate();
+    }
+
+    /**
+     * Gets the total number of times the cache lookup method returned a cached or uncached value.
+     */
+    public long getClassCacheRequestCount() {
+        return classMap.stats().missCount();
+    }
+
+    /**
+     * Gets the total number of nanoseconds that the cache spent compiling scripts.
+     */
+    public long getClassCacheTotalLoadTime() {
+        return classMap.stats().totalLoadTime();
+    }
+
     Class getScriptClass(final String script) throws CompilationFailedException {
         try {
             return classMap.get(script).get();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ffa5af6/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
index f5dd9c5..b87d0ac 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
@@ -47,11 +47,11 @@ public class GremlinGroovyScriptEngineCompilationOptionsTest {
             b.put("x" + ix, ix);
         }
 
-        assertEquals(0, engine.getLongRunCompilationCount());
+        assertEquals(0, engine.getClassCacheLongRunCompilationCount());
 
         engine.eval(script, b);
 
-        assertEquals(1, engine.getLongRunCompilationCount());
+        assertEquals(1, engine.getClassCacheLongRunCompilationCount());
     }
 
     @Test
@@ -71,10 +71,10 @@ public class GremlinGroovyScriptEngineCompilationOptionsTest {
             b.put("x" + ix, ix);
         }
 
-        assertEquals(0, engine.getLongRunCompilationCount());
+        assertEquals(0, engine.getClassCacheLongRunCompilationCount());
 
         engine.eval(script, b);
 
-        assertEquals(1, engine.getLongRunCompilationCount());
+        assertEquals(1, engine.getClassCacheLongRunCompilationCount());
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ffa5af6/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index eb0a44b..0606721 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -497,7 +497,7 @@ public class GremlinGroovyScriptEngineTest {
     }
 
     @Test
-    public void testInvokeFunctionRedirectsOutputToContextOut() throws Exception {
+    public void shouldInvokeFunctionRedirectsOutputToContextOut() throws Exception {
         final GremlinGroovyScriptEngine  engine = new GremlinGroovyScriptEngine();
         StringWriter writer = new StringWriter();
         final StringWriter unusedWriter = new StringWriter();
@@ -520,7 +520,7 @@ public class GremlinGroovyScriptEngineTest {
     }
 
     @Test
-    public void testEngineContextAccessibleToScript() throws Exception {
+    public void shouldEnableEngineContextAccessibleToScript() throws Exception {
         final GremlinGroovyScriptEngine  engine = new GremlinGroovyScriptEngine();
         final ScriptContext engineContext = engine.getContext();
         engine.put("theEngineContext", engineContext);
@@ -529,7 +529,7 @@ public class GremlinGroovyScriptEngineTest {
     }
 
     @Test
-    public void testContextBindingOverridesEngineContext() throws Exception {
+    public void shouldEnableContextBindingOverridesEngineContext() throws Exception {
         final GremlinGroovyScriptEngine  engine = new GremlinGroovyScriptEngine();
         final ScriptContext engineContext = engine.getContext();
         final Map<String,Object> otherContext = new HashMap<>();
@@ -539,4 +539,68 @@ public class GremlinGroovyScriptEngineTest {
         final String code = "[answer: context.is(theEngineContext) ? \"wrong\" : context.foo]";
         assertEquals("bar", ((Map) engine.eval(code)).get("answer"));
     }
+
+    @Test
+    public void shouldGetClassMapCacheBasicStats() throws Exception {
+        final GremlinGroovyScriptEngine  engine = new GremlinGroovyScriptEngine();
+        assertEquals(0, engine.getClassCacheEstimatedSize());
+        assertEquals(0, engine.getClassCacheHitCount());
+        assertEquals(0, engine.getClassCacheLoadCount());
+        assertEquals(0, engine.getClassCacheLoadFailureCount());
+        assertEquals(0, engine.getClassCacheLoadSuccessCount());
+
+        engine.eval("1+1");
+
+        assertEquals(1, engine.getClassCacheEstimatedSize());
+        assertEquals(0, engine.getClassCacheHitCount());
+        assertEquals(1, engine.getClassCacheLoadCount());
+        assertEquals(0, engine.getClassCacheLoadFailureCount());
+        assertEquals(1, engine.getClassCacheLoadSuccessCount());
+
+        for (int ix = 0; ix < 100; ix++) {
+            engine.eval("1+1");
+        }
+
+        assertEquals(1, engine.getClassCacheEstimatedSize());
+        assertEquals(100, engine.getClassCacheHitCount());
+        assertEquals(1, engine.getClassCacheLoadCount());
+        assertEquals(0, engine.getClassCacheLoadFailureCount());
+        assertEquals(1, engine.getClassCacheLoadSuccessCount());
+
+        for (int ix = 0; ix < 100; ix++) {
+            engine.eval("1+" + ix);
+        }
+
+        assertEquals(100, engine.getClassCacheEstimatedSize());
+        assertEquals(101, engine.getClassCacheHitCount());
+        assertEquals(100, engine.getClassCacheLoadCount());
+        assertEquals(0, engine.getClassCacheLoadFailureCount());
+        assertEquals(100, engine.getClassCacheLoadSuccessCount());
+
+        try {
+            engine.eval("(me broken");
+            fail("Should have tanked with compilation error");
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(ScriptException.class));
+        }
+
+        assertEquals(101, engine.getClassCacheEstimatedSize());
+        assertEquals(101, engine.getClassCacheHitCount());
+        assertEquals(101, engine.getClassCacheLoadCount());
+        assertEquals(1, engine.getClassCacheLoadFailureCount());
+        assertEquals(100, engine.getClassCacheLoadSuccessCount());
+
+        try {
+            engine.eval("(me broken");
+            fail("Should have tanked with compilation error");
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(ScriptException.class));
+        }
+
+        assertEquals(101, engine.getClassCacheEstimatedSize());
+        assertEquals(102, engine.getClassCacheHitCount());
+        assertEquals(101, engine.getClassCacheLoadCount());
+        assertEquals(1, engine.getClassCacheLoadFailureCount());
+        assertEquals(100, engine.getClassCacheLoadSuccessCount());
+    }
 }
\ No newline at end of file


[06/20] tinkerpop git commit: TINKERPOP-1644 Fix exception handling.

Posted by sp...@apache.org.
TINKERPOP-1644
Fix exception handling.


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

Branch: refs/heads/master
Commit: 1df71c81e032daa9c9db6f626d99c39b37d434ce
Parents: 17a72e0
Author: BrynCooke <br...@gmail.com>
Authored: Wed Mar 8 13:26:31 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 .../tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1df71c81/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 2151a82..cadc3b0 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -174,7 +174,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
                     return loader.parseClass(script, generateScriptName());
                 } catch (CompilationFailedException e) {
                     long finish = System.currentTimeMillis();
-                    log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e.getCause());
+                    log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e);
                     throw e;
                 } finally {
                     long time = System.currentTimeMillis() - start;


[07/20] tinkerpop git commit: TINKERPOP-1644 Improve script compilation syncronisation Script compilation is synchronised. Script compilation times are placed in to logs. Failed scripts will not be recompiled. Scripts that take over 5 seconds to compile

Posted by sp...@apache.org.
TINKERPOP-1644 Improve script compilation syncronisation
Script compilation is synchronised.
Script compilation times are placed in to logs.
Failed scripts will not be recompiled.
Scripts that take over 5 seconds to compile are logged as a warning.


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

Branch: refs/heads/master
Commit: 13c93cabac51112a73f592e0fba12e515f643522
Parents: 60a3fb3
Author: BrynCooke <br...@gmail.com>
Authored: Thu Mar 2 19:07:28 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  4 ++
 .../jsr223/GremlinGroovyScriptEngine.java       | 57 ++++++++++++++++++--
 2 files changed, 56 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/13c93cab/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6861d57..24e5e9c 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,10 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Script compilation is synchronised.
+* Script compilation times are placed in to logs.
+* Failed scripts will not be recompiled.
+* Scripts that take over 5 seconds to compile are logged as a warning.
 * Fixed an `NullPointerException` in `GraphMLReader` that occurred when an `<edge>` didn't have an ID field and the base graph supported ID assignment.
 * Split `ComputerVerificationStrategy` into two strategies: `ComputerVerificationStrategy` and `ComputerFinalizationStrategy`.
 * Removed `HasTest.g_V_hasId_compilationEquality` from process test suite as it makes too many assumptions about provider compilation.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/13c93cab/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 1fb2efc..a8365a2 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -56,6 +56,8 @@ import org.codehaus.groovy.runtime.InvokerHelper;
 import org.codehaus.groovy.runtime.MetaClassHelper;
 import org.codehaus.groovy.runtime.MethodClosure;
 import org.codehaus.groovy.util.ReferenceBundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.script.Bindings;
 import javax.script.CompiledScript;
@@ -93,6 +95,7 @@ import java.util.stream.Collectors;
 public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         implements DependencyManager, AutoCloseable, GremlinScriptEngine {
 
+    private static final Logger log = LoggerFactory.getLogger(GremlinGroovyScriptEngine.class);
     /**
      * An "internal" key for sandboxing the script engine - technically not for public use.
      */
@@ -153,6 +156,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
      * Script to generated Class map.
      */
     private ManagedConcurrentValueMap<String, Class> classMap = new ManagedConcurrentValueMap<>(ReferenceBundle.getSoftBundle());
+    private ManagedConcurrentValueMap<String, CompilationFailedException> failedClassMap = new ManagedConcurrentValueMap<>(ReferenceBundle.getSoftBundle());
 
     /**
      * Global closures map - this is used to simulate a single global functions namespace
@@ -529,13 +533,56 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         return makeInterface(thiz, clazz);
     }
 
+    private Class getScriptClassFromMap(String script) throws CompilationFailedException {
+        CompilationFailedException exception = failedClassMap.get(script);
+        if(exception != null) {
+            throw exception;
+        }
+        return classMap.get(script);
+
+    }
+
     Class getScriptClass(final String script) throws CompilationFailedException {
-        Class clazz = classMap.get(script);
-        if (clazz != null) return clazz;
+        Class clazz = getScriptClassFromMap(script);
+        if (clazz != null) {
+            return clazz;
+        }
+        synchronized (this) {
+            clazz = getScriptClassFromMap(script);
+            if (clazz != null) {
+                return clazz;
+            }
 
-        clazz = loader.parseClass(script, generateScriptName());
-        classMap.put(script, clazz);
-        return clazz;
+            long start = System.currentTimeMillis();
+            try {
+                clazz = loader.parseClass(script, generateScriptName());
+                long time = System.currentTimeMillis() - start;
+                if(time > 5000) {
+                    //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
+                    //Scripts with a large numbers of parameters often trigger this and should be avoided.
+                    log.warn("Script compilation {} took {}ms", script, time);
+                }
+                else {
+                    log.debug("Script compilation {} took {}ms", script, time);
+                }
+
+
+            }
+            catch(CompilationFailedException t) {
+                long finish = System.currentTimeMillis();
+                log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, t);
+                failedClassMap.put(script, t);
+                throw t;
+            }
+            catch(Throwable t) {
+                long finish = System.currentTimeMillis();
+                log.error("Script compilation FAILED with throwable {} took {}ms {}", script, finish - start, t);
+                throw t;
+            }
+            classMap.put(script, clazz);
+
+            return clazz;
+        }
     }
 
     boolean isCached(final String script) {


[14/20] tinkerpop git commit: TINKERPOP-1644 Exposed GremlinScriptEngine metrics in Gremlin Server

Posted by sp...@apache.org.
TINKERPOP-1644 Exposed GremlinScriptEngine metrics in Gremlin Server


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

Branch: refs/heads/master
Commit: b689deb1dd1a0c745966a1ed5f8e7e3b2d543af2
Parents: 8ffa5af
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 12:25:35 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:13:03 2017 -0500

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  2 +-
 .../gremlin/groovy/engine/ScriptEngines.java    |  7 ++
 .../gremlin/server/op/session/Session.java      | 27 +++++++
 .../gremlin/server/util/MetricManager.java      | 79 +++++++++++++++++---
 .../server/util/ServerGremlinExecutor.java      | 15 ++++
 5 files changed, 118 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b689deb1/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 3729271..a306dea 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,7 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-* Added various metrics to the `GremlinGroovyScriptEngine` around script compilation.
+* Added various metrics to the `GremlinGroovyScriptEngine` around script compilation and exposed them in Gremlin Server.
 * Moved the `caffeine` dependency down to `gremlin-groovy` and out of `gremlin-server`.
 * Improved script compilation in `GremlinGroovyScriptEngine to use better caching, log long compile times and prevent failed compilations from recompiling on future requests.
 * Script compilation is synchronised.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b689deb1/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
index 7dcfc5c..6dfd87a 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
@@ -311,6 +311,13 @@ public class ScriptEngines implements AutoCloseable {
     }
 
     /**
+     * Gets an {@link GremlinScriptEngine} by its name.
+     */
+    public GremlinScriptEngine getEngineByName(final String engineName) {
+        return scriptEngines.get(engineName);
+    }
+
+    /**
      * Get the set of {@code ScriptEngine} that implement {@link DependencyManager} interface.
      */
     private Set<DependencyManager> getDependencyManagers() {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b689deb1/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
index 9b16a3b..b8cb28c 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
@@ -18,11 +18,16 @@
  */
 package org.apache.tinkerpop.gremlin.server.op.session;
 
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricFilter;
 import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
+import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
 import org.apache.tinkerpop.gremlin.server.Context;
 import org.apache.tinkerpop.gremlin.server.GraphManager;
 import org.apache.tinkerpop.gremlin.server.Settings;
 import org.apache.tinkerpop.gremlin.server.util.LifeCycleHook;
+import org.apache.tinkerpop.gremlin.server.util.MetricManager;
 import org.apache.tinkerpop.gremlin.server.util.ThreadFactoryUtil;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.slf4j.Logger;
@@ -30,6 +35,7 @@ import org.slf4j.LoggerFactory;
 
 import javax.script.Bindings;
 import javax.script.SimpleBindings;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
@@ -92,6 +98,15 @@ public class Session {
                 SessionOpProcessor.CONFIG_PER_GRAPH_CLOSE_TIMEOUT, SessionOpProcessor.DEFAULT_PER_GRAPH_CLOSE_TIMEOUT).toString());
 
         this.gremlinExecutor = initializeGremlinExecutor().create();
+
+        settings.scriptEngines.keySet().forEach(engineName -> {
+            try {
+                gremlinExecutor.eval("1+1", engineName, Collections.emptyMap()).join();
+                registerMetrics(engineName);
+            } catch (Exception ex) {
+                logger.warn(String.format("Could not initialize {} ScriptEngine as script could not be evaluated - %s", engineName), ex);
+            }
+        });
     }
 
     public GremlinExecutor getGremlinExecutor() {
@@ -207,6 +222,10 @@ public class Session {
         executor.shutdownNow();
 
         sessions.remove(session);
+
+        // once a session is dead release the gauges in the registry for it
+        MetricManager.INSTANCE.getRegistry().removeMatching((s, metric) -> s.contains(session));
+
         logger.info("Session {} closed", session);
     }
 
@@ -244,4 +263,12 @@ public class Session {
 
         return gremlinExecutorBuilder;
     }
+
+    private void registerMetrics(final String engineName) {
+        final ScriptEngines scriptEngines = gremlinExecutor.getScriptEngines();
+        final GremlinScriptEngine engine = null == scriptEngines ?
+                gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
+                scriptEngines.getEngineByName(engineName);
+        MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, "session", session, "class-cache");
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b689deb1/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
index 2867aa7..06179d2 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
@@ -33,6 +33,9 @@ import com.codahale.metrics.ganglia.GangliaReporter;
 import com.codahale.metrics.graphite.Graphite;
 import com.codahale.metrics.graphite.GraphiteReporter;
 import info.ganglia.gmetric4j.gmetric.GMetric;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,17 +69,16 @@ public enum MetricManager {
     private GraphiteReporter graphiteReporter = null;
 
     /**
-     * Return the Titan Metrics registry.
+     * Return the {@code MetricsRegistry}.
      *
-     * @return the single {@code MetricRegistry} used for all of Titan's Metrics
-     * monitoring
+     * @return the single {@code MetricRegistry} used for all of monitoring
      */
     public MetricRegistry getRegistry() {
         return registry;
     }
 
     /**
-     * Create a {@link ConsoleReporter} attached to the Titan Metrics registry.
+     * Create a {@link ConsoleReporter} attached to the {@code MetricsRegistry}.
      *
      * @param reportIntervalInMS milliseconds to wait between dumping metrics to the console
      */
@@ -106,7 +108,7 @@ public enum MetricManager {
     }
 
     /**
-     * Create a {@link CsvReporter} attached to the Titan Metrics registry.
+     * Create a {@link CsvReporter} attached to the {@code MetricsRegistry}.
      * <p/>
      * The {@code output} argument must be non-null but need not exist. If it
      * doesn't already exist, this method attempts to create it by calling
@@ -153,7 +155,7 @@ public enum MetricManager {
     }
 
     /**
-     * Create a {@link JmxReporter} attached to the Titan Metrics registry.
+     * Create a {@link JmxReporter} attached to the {@code MetricsRegistry}.
      * <p/>
      * If {@code domain} or {@code agentId} is null, then Metrics's uses its own
      * internal default value(s).
@@ -210,7 +212,7 @@ public enum MetricManager {
     }
 
     /**
-     * Create a {@link Slf4jReporter} attached to the Titan Metrics registry.
+     * Create a {@link Slf4jReporter} attached to the {@code MetricsRegistry}.
      * <p/>
      * If {@code loggerName} is null, or if it is non-null but
      * LoggerFactory.getLogger(loggerName) returns null, then Metrics's
@@ -257,7 +259,7 @@ public enum MetricManager {
     }
 
     /**
-     * Create a {@link GangliaReporter} attached to the Titan Metrics registry.
+     * Create a {@link GangliaReporter} attached to the {@code MetricsRegistry}.
      * <p/>
      * {@code groupOrHost} and {@code addressingMode} must be non-null. The
      * remaining non-primitive arguments may be null. If {@code protocol31} is
@@ -321,7 +323,7 @@ public enum MetricManager {
     }
 
     /**
-     * Create a {@link GraphiteReporter} attached to the Titan Metrics registry.
+     * Create a {@link GraphiteReporter} attached to the {@code MetricsRegistry}.
      * <p/>
      * If {@code prefix} is null, then Metrics's internal default prefix is used
      * (empty string at the time this comment was written).
@@ -367,8 +369,7 @@ public enum MetricManager {
     }
 
     /**
-     * Remove all Titan Metrics reporters previously configured through the
-     * {@code add*} methods on this class.
+     * Remove all reporters previously configured through the {@code add*} methods on this class.
      */
     public synchronized void removeAllReporters() {
         removeConsoleReporter();
@@ -418,4 +419,60 @@ public enum MetricManager {
     public Histogram getHistogram(final String prefix, final String... names) {
         return getRegistry().histogram(MetricRegistry.name(prefix, names));
     }
+
+    /**
+     * Registers metrics from a {@link GremlinScriptEngine}. At this point, this only works for the
+     * {@link GremlinGroovyScriptEngine} as it is the only one that collects metrics at this point. As the
+     * {@link GremlinScriptEngine} implementations achieve greater parity these metrics will get expanded.
+     */
+    public void registerGremlinScriptEngineMetrics(final GremlinScriptEngine engine, final String... prefix) {
+        if (engine instanceof GremlinGroovyScriptEngine) {
+            final GremlinGroovyScriptEngine gremlinGroovyScriptEngine = (GremlinGroovyScriptEngine) engine;
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "long-run-compilation-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLongRunCompilationCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "estimated-size")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheEstimatedSize);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "average-load-penalty")),
+                    (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheAverageLoadPenalty);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "eviction-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheEvictionCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "eviction-weight")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheEvictionWeight);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "hit-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheHitCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "hit-rate")),
+                    (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheHitRate);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLoadCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-failure-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLoadFailureCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-failure-rate")),
+                    (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheLoadFailureRate);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-success-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLoadSuccessCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "miss-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheMissCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "miss-rate")),
+                    (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheMissRate);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "request-count")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheRequestCount);
+            MetricManager.INSTANCE.getRegistry().register(
+                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "total-load-time")),
+                    (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheTotalLoadTime);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b689deb1/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index b9b7280..d66e0e8 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@ -18,7 +18,11 @@
  */
 package org.apache.tinkerpop.gremlin.server.util;
 
+import com.codahale.metrics.Gauge;
 import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
+import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
 import org.apache.tinkerpop.gremlin.server.Channelizer;
 import org.apache.tinkerpop.gremlin.server.GraphManager;
@@ -39,6 +43,8 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadFactory;
 import java.util.stream.Collectors;
 
+import static com.codahale.metrics.MetricRegistry.name;
+
 /**
  * The core of script execution in Gremlin Server.  Given {@link Settings} and optionally other arguments, this
  * class will construct a {@link GremlinExecutor} to be used by Gremlin Server.  A typical usage would be to
@@ -152,6 +158,7 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> {
         settings.scriptEngines.keySet().forEach(engineName -> {
             try {
                 gremlinExecutor.eval("1+1", engineName, Collections.emptyMap()).join();
+                registerMetrics(engineName);
             } catch (Exception ex) {
                 logger.warn(String.format("Could not initialize {} ScriptEngine as script could not be evaluated - %s", engineName), ex);
             }
@@ -179,6 +186,14 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> {
                 .collect(Collectors.toList());
     }
 
+    private void registerMetrics(final String engineName) {
+        final ScriptEngines scriptEngines = gremlinExecutor.getScriptEngines();
+        final GremlinScriptEngine engine = null == scriptEngines ?
+                gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
+                scriptEngines.getEngineByName(engineName);
+        MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, "sessionless", "class-cache");
+    }
+
     public void addHostOption(final String key, final Object value) {
         hostOptions.put(key, value);
     }


[11/20] tinkerpop git commit: TINKERPOP-1644 Docs for new metrics in Gremlin Server

Posted by sp...@apache.org.
TINKERPOP-1644 Docs for new metrics in Gremlin Server


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

Branch: refs/heads/master
Commit: 37976526f1eac9fd06858f962f979aa98d3e5346
Parents: 9eb248e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 13:35:44 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:13:03 2017 -0500

----------------------------------------------------------------------
 docs/src/reference/gremlin-applications.asciidoc   |  5 +++++
 docs/src/upgrade/release-3.2.x-incubating.asciidoc | 10 ++++++++++
 2 files changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37976526/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 8e0edc2..37244e0 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -1560,6 +1560,11 @@ and standard deviation evaluation times, as well as the 75th, 95th, 98th, 99th a
 * `op.traversal` - the number of `Traveral` executions, mean rate, 1, 5, and 15 minute rates, minimum, maximum, median,
 mean, and standard deviation evaluation times, as well as the 75th, 95th, 98th, 99th and 99.9th percentile evaluation
 times.
+* `engine-name.session.session-id.*` - metrics related to different `GremlinScriptEngine` instanc configured for
+session-based requests where "engine-name" will be the actual name of the engine, such as "gremlin-groovy" and
+"session-id" will be the identifier for the session itself.
+* `engine-name.sessionless.*` - metrics related to different `GremlinScriptEngine` instanc configured for sessionless
+requests where "engine-name" will be the actual name of the engine, such as "gremlin-groovy".
 
 Best Practices
 ~~~~~~~~~~~~~~

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37976526/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.2.x-incubating.asciidoc b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
index 78c276b..d01f58f 100644
--- a/docs/src/upgrade/release-3.2.x-incubating.asciidoc
+++ b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
@@ -32,6 +32,16 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.2.5/CHANGELOG.asc
 Upgrading for Users
 ~~~~~~~~~~~~~~~~~~~
 
+GremlinScriptEngine Metrics
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The `GremlinScriptEngine` has a number of new metrics about its cache size and script compilation times which should
+be helpful in understanding usage problems. As `GremlinScriptEngine` instances are used in Gremlin Server these metrics
+are naturally exposed as part of the standard link:http://tinkerpop.apache.org/docs/current/reference/#_metrics[metrics]
+set. Note that metrics are captured for both sessionless requests as well as for each individual session that is opened.
+
+See: https://issues.apache.org/jira/browse/TINKERPOP-1644[TINKERPOP-1644]
+
 Gremlin-Python Driver
 ^^^^^^^^^^^^^^^^^^^^^
 Gremlin-Python now offers a more complete driver implementation that uses connection pooling and


[19/20] tinkerpop git commit: TINKERPOP-1644 Added some docs for CompilationOptionsCustomizerProvider

Posted by sp...@apache.org.
TINKERPOP-1644 Added some docs for CompilationOptionsCustomizerProvider


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

Branch: refs/heads/master
Commit: d7c2a221ecb56442a01ca2e5cf539b011ac05f94
Parents: 33416dd
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Mar 14 15:26:46 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Mar 14 15:26:46 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/gremlin-applications.asciidoc | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d7c2a221/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 884ce04..3a2c446 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -1336,6 +1336,7 @@ There are a number of pre-packaged `CustomizerProvider` implementations:
 |=========================================================
 |Customizer |Description
 |`CompileStaticCustomizerProvider` |Applies `CompileStatic` annotations to incoming scripts thus removing dynamic dispatch. More information about static compilation can be found in the link:http://docs.groovy-lang.org/latest/html/documentation/#_static_compilation[Groovy Documentation].  It is possible to configure this `CustomizerProvider` by specifying a comma separated list of link:http://docs.groovy-lang.org/latest/html/documentation/#Typecheckingextensions-Workingwithextensions[type checking extensions] that can have the effect of securing calls to various methods.
+|`CompilationOptionsCustomizerProvider` |The amount of time a script is allowed to compile before a warning message is sent to the logs.
 |`ConfigurationCustomizerProvider` |Allows configuration of the Groovy `CompilerConfiguration` object by taking a `Map` of key/value pairs where the "key" is a property to set on the `CompilerConfiguration`.
 |`ThreadInterruptCustomizerProvider` |Injects checks for thread interruption, thus allowing the thread to potentially respect calls to `Thread.interrupt()`
 |`TimedInterruptCustomizerProvider` |Injects checks into loops to interrupt them if they exceed the configured timeout in milliseconds.
@@ -1354,6 +1355,7 @@ scriptEngines: {
       compilerCustomizerProviders: {
         "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ThreadInterruptCustomizerProvider":[],
         "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider":[10000],
+        "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompilationOptionsCustomizerProvider":[8000],
         "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider":["org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension"]}}}}
 
 NOTE: The above configuration could also use the `TypeCheckedCustomizerProvider` in place of the


[13/20] tinkerpop git commit: TINKERPOP-1644 Renamed metrics for GremlinScriptEngine instances.

Posted by sp...@apache.org.
TINKERPOP-1644 Renamed metrics for GremlinScriptEngine instances.

Included the name of the GremlinScriptEngine and prefixed each metric with GremlinServer class name to be consistent with other metrics.


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

Branch: refs/heads/master
Commit: 9eb248ef0f0f29e8cf11cd5391ef8d993e37f7af
Parents: b689deb
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 13:15:04 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:13:03 2017 -0500

----------------------------------------------------------------------
 .../gremlin/server/op/session/Session.java      |  2 +-
 .../gremlin/server/util/MetricManager.java      | 31 ++++++++++----------
 .../server/util/ServerGremlinExecutor.java      |  2 +-
 3 files changed, 18 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9eb248ef/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
index b8cb28c..6961339 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
@@ -269,6 +269,6 @@ public class Session {
         final GremlinScriptEngine engine = null == scriptEngines ?
                 gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
                 scriptEngines.getEngineByName(engineName);
-        MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, "session", session, "class-cache");
+        MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, engineName, "session", session, "class-cache");
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9eb248ef/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
index 06179d2..faec502 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/MetricManager.java
@@ -36,6 +36,7 @@ import info.ganglia.gmetric4j.gmetric.GMetric;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
 import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
+import org.apache.tinkerpop.gremlin.server.GremlinServer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -429,49 +430,49 @@ public enum MetricManager {
         if (engine instanceof GremlinGroovyScriptEngine) {
             final GremlinGroovyScriptEngine gremlinGroovyScriptEngine = (GremlinGroovyScriptEngine) engine;
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "long-run-compilation-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "long-run-compilation-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLongRunCompilationCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "estimated-size")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "estimated-size")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheEstimatedSize);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "average-load-penalty")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "average-load-penalty")),
                     (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheAverageLoadPenalty);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "eviction-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "eviction-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheEvictionCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "eviction-weight")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "eviction-weight")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheEvictionWeight);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "hit-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "hit-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheHitCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "hit-rate")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "hit-rate")),
                     (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheHitRate);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "load-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLoadCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-failure-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "load-failure-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLoadFailureCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-failure-rate")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "load-failure-rate")),
                     (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheLoadFailureRate);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "load-success-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "load-success-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheLoadSuccessCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "miss-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "miss-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheMissCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "miss-rate")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "miss-rate")),
                     (Gauge<Double>) gremlinGroovyScriptEngine::getClassCacheMissRate);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "request-count")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "request-count")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheRequestCount);
             MetricManager.INSTANCE.getRegistry().register(
-                    MetricRegistry.name(GremlinGroovyScriptEngine.class, ArrayUtils.add(prefix, "total-load-time")),
+                    MetricRegistry.name(GremlinServer.class, ArrayUtils.add(prefix, "total-load-time")),
                     (Gauge<Long>) gremlinGroovyScriptEngine::getClassCacheTotalLoadTime);
         }
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9eb248ef/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index d66e0e8..e3c0cae 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@ -191,7 +191,7 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> {
         final GremlinScriptEngine engine = null == scriptEngines ?
                 gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
                 scriptEngines.getEngineByName(engineName);
-        MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, "sessionless", "class-cache");
+        MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, engineName, "sessionless", "class-cache");
     }
 
     public void addHostOption(final String key, final Object value) {


[03/20] tinkerpop git commit: TINKERPOP-1644 Minor code format updates

Posted by sp...@apache.org.
TINKERPOP-1644 Minor code format updates


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

Branch: refs/heads/master
Commit: de1d58ab33c3121e9bafb5e4908f3e0d76c8e26e
Parents: 608f024
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 13:37:42 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 .../groovy/jsr223/GremlinGroovyScriptEngine.java        | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/de1d58ab/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index cadc3b0..42d954a 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -164,20 +164,20 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     /**
      * Script to generated Class map.
      */
-    private LoadingCache<String, Future<Class>> classMap = Caffeine.newBuilder().softValues().build(new CacheLoader<String, Future<Class>>() {
+    private final LoadingCache<String, Future<Class>> classMap = Caffeine.newBuilder().softValues().build(new CacheLoader<String, Future<Class>>() {
         @Override
-        public Future<Class> load(String script) throws Exception {
-            long start = System.currentTimeMillis();
+        public Future<Class> load(final String script) throws Exception {
+            final long start = System.currentTimeMillis();
 
             return CompletableFuture.supplyAsync(() -> {
                 try {
                     return loader.parseClass(script, generateScriptName());
                 } catch (CompilationFailedException e) {
-                    long finish = System.currentTimeMillis();
+                    final long finish = System.currentTimeMillis();
                     log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e);
                     throw e;
                 } finally {
-                    long time = System.currentTimeMillis() - start;
+                    final long time = System.currentTimeMillis() - start;
                     if (time > 5000) {
                         //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
                         //Scripts with a large numbers of parameters often trigger this and should be avoided.
@@ -186,7 +186,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
                         log.debug("Script compilation {} took {}ms", script, time);
                     }
                 }
-            }, command -> command.run());
+            }, Runnable::run);
         }
 
     });


[08/20] tinkerpop git commit: TINKERPOP-1644 Fix exception handling.

Posted by sp...@apache.org.
TINKERPOP-1644
Fix exception handling.


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

Branch: refs/heads/master
Commit: 17a72e0e1db6fe52d3a0821ef2bfae1eb39be856
Parents: 18778e4
Author: BrynCooke <br...@gmail.com>
Authored: Wed Mar 8 13:23:30 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 .../jsr223/GremlinGroovyScriptEngine.java       | 33 ++++++++++----------
 1 file changed, 16 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/17a72e0e/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 51850ad..2151a82 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -168,26 +168,25 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         @Override
         public Future<Class> load(String script) throws Exception {
             long start = System.currentTimeMillis();
-            try {
-                return CompletableFuture.supplyAsync(() -> loader.parseClass(script, generateScriptName()), command -> command.run());
-            } catch (Exception e) {
-                if (e.getCause() instanceof CompilationFailedException) {
+
+            return CompletableFuture.supplyAsync(() -> {
+                try {
+                    return loader.parseClass(script, generateScriptName());
+                } catch (CompilationFailedException e) {
                     long finish = System.currentTimeMillis();
                     log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e.getCause());
-                    throw (CompilationFailedException) e.getCause();
-                } else {
-                    throw new AssertionError("Unexpected exception when compiling script", e);
-                }
-            } finally {
-                long time = System.currentTimeMillis() - start;
-                if (time > 5000) {
-                    //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
-                    //Scripts with a large numbers of parameters often trigger this and should be avoided.
-                    log.warn("Script compilation {} took {}ms", script, time);
-                } else {
-                    log.debug("Script compilation {} took {}ms", script, time);
+                    throw e;
+                } finally {
+                    long time = System.currentTimeMillis() - start;
+                    if (time > 5000) {
+                        //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
+                        //Scripts with a large numbers of parameters often trigger this and should be avoided.
+                        log.warn("Script compilation {} took {}ms", script, time);
+                    } else {
+                        log.debug("Script compilation {} took {}ms", script, time);
+                    }
                 }
-            }
+            }, command -> command.run());
         }
 
     });


[15/20] tinkerpop git commit: TINKERPOP-1644 Cleaned up a bad import

Posted by sp...@apache.org.
TINKERPOP-1644 Cleaned up a bad import


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

Branch: refs/heads/master
Commit: 33db1a3893c91a2dde100c8a0289312d4550503c
Parents: 3797652
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 14:51:36 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:13:03 2017 -0500

----------------------------------------------------------------------
 .../groovy/jsr223/GroovyCompilerGremlinPluginTest.java        | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/33db1a38/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
index bacfc90..d8cf571 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
@@ -26,7 +26,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
 
-import static org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyCompilerGremlinPlugin.*;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsInstanceOf.instanceOf;
@@ -40,7 +39,7 @@ public class GroovyCompilerGremlinPluginTest {
     @Test
     public void shouldConfigureForGroovyOnly() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
-                compilation(Compilation.COMPILE_STATIC).create();
+                compilation(GroovyCompilerGremlinPlugin.Compilation.COMPILE_STATIC).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-not-real");
         assertThat(customizers.isPresent(), is(false));
     }
@@ -49,7 +48,7 @@ public class GroovyCompilerGremlinPluginTest {
     public void shouldConfigureWithCompileStatic() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
                 expectedCompilationTime(0).
-                compilation(Compilation.COMPILE_STATIC).create();
+                compilation(GroovyCompilerGremlinPlugin.Compilation.COMPILE_STATIC).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
         assertEquals(1, customizers.get().length);
@@ -60,7 +59,7 @@ public class GroovyCompilerGremlinPluginTest {
     public void shouldConfigureWithTypeChecked() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
                 expectedCompilationTime(0).
-                compilation(Compilation.TYPE_CHECKED).create();
+                compilation(GroovyCompilerGremlinPlugin.Compilation.TYPE_CHECKED).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
         assertEquals(1, customizers.get().length);


[18/20] tinkerpop git commit: TINKERPOP-1644 Minor fixup of variable assignment

Posted by sp...@apache.org.
TINKERPOP-1644 Minor fixup of variable assignment


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

Branch: refs/heads/master
Commit: 33416ddd743f6c726ccb9d91d5959ae50c60bab3
Parents: 7fced96
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Mar 14 12:43:58 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Mar 14 12:43:58 2017 -0400

----------------------------------------------------------------------
 .../jsr223/customizer/CompilationOptionsCustomizerProvider.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/33416ddd/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
index 00a20f1..58b304f 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
@@ -38,7 +38,7 @@ public class CompilationOptionsCustomizerProvider implements CompilerCustomizerP
     }
 
     public CompilationOptionsCustomizerProvider(final Long expectedCompilationTime) {
-        this.expectedCompilationTime = expectedCompilationTime.intValue();
+        this.expectedCompilationTime = expectedCompilationTime;
     }
 
     public long getExpectedCompilationTime() {


[09/20] tinkerpop git commit: TINKERPOP-1644 Use Caffeine cache

Posted by sp...@apache.org.
TINKERPOP-1644
Use Caffeine cache


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

Branch: refs/heads/master
Commit: 18778e405981523355319fa56bd04fd6cc07b845
Parents: deb6828
Author: BrynCooke <br...@gmail.com>
Authored: Wed Mar 8 12:24:46 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 gremlin-groovy/pom.xml                          |  5 ++
 .../jsr223/GremlinGroovyScriptEngine.java       | 75 +++++++++++---------
 2 files changed, 48 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/18778e40/gremlin-groovy/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-groovy/pom.xml b/gremlin-groovy/pom.xml
index 511952a..474b458 100644
--- a/gremlin-groovy/pom.xml
+++ b/gremlin-groovy/pom.xml
@@ -70,6 +70,11 @@ limitations under the License.
             <artifactId>jbcrypt</artifactId>
             <version>0.4</version>
         </dependency>
+        <dependency>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>caffeine</artifactId>
+            <version>2.3.1</version>
+        </dependency>
         <!-- TEST -->
         <dependency>
             <groupId>org.slf4j</groupId>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/18778e40/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 67275f8..51850ad 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -18,6 +18,9 @@
  */
 package org.apache.tinkerpop.gremlin.groovy.jsr223;
 
+import com.github.benmanes.caffeine.cache.CacheLoader;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
 import groovy.grape.Grape;
 import groovy.lang.Binding;
 import groovy.lang.Closure;
@@ -80,6 +83,8 @@ import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.regex.Pattern;
@@ -154,17 +159,44 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         }
     };
 
+    private GremlinGroovyClassLoader loader;
+
     /**
      * Script to generated Class map.
      */
-    private ManagedConcurrentValueMap<String, Future<Class>> classMap = new ManagedConcurrentValueMap<>(ReferenceBundle.getSoftBundle());
+    private LoadingCache<String, Future<Class>> classMap = Caffeine.newBuilder().softValues().build(new CacheLoader<String, Future<Class>>() {
+        @Override
+        public Future<Class> load(String script) throws Exception {
+            long start = System.currentTimeMillis();
+            try {
+                return CompletableFuture.supplyAsync(() -> loader.parseClass(script, generateScriptName()), command -> command.run());
+            } catch (Exception e) {
+                if (e.getCause() instanceof CompilationFailedException) {
+                    long finish = System.currentTimeMillis();
+                    log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e.getCause());
+                    throw (CompilationFailedException) e.getCause();
+                } else {
+                    throw new AssertionError("Unexpected exception when compiling script", e);
+                }
+            } finally {
+                long time = System.currentTimeMillis() - start;
+                if (time > 5000) {
+                    //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
+                    //Scripts with a large numbers of parameters often trigger this and should be avoided.
+                    log.warn("Script compilation {} took {}ms", script, time);
+                } else {
+                    log.debug("Script compilation {} took {}ms", script, time);
+                }
+            }
+        }
+
+    });
 
     /**
      * Global closures map - this is used to simulate a single global functions namespace
      */
     private ManagedConcurrentValueMap<String, Closure> globalClosures = new ManagedConcurrentValueMap<>(ReferenceBundle.getHardBundle());
 
-    private GremlinGroovyClassLoader loader;
 
     private AtomicLong counter = new AtomicLong(0L);
 
@@ -420,7 +452,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
 
         // must clear the local cache here because the classloader has been reset.  therefore, classes previously
         // referenced before that might not have evaluated might cleanly evaluate now.
-        classMap.clear();
+        classMap.invalidateAll();
         globalClosures.clear();
 
         final Set<Artifact> toReuse = new HashSet<>(artifactsToUse);
@@ -535,41 +567,20 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     }
 
     Class getScriptClass(final String script) throws CompilationFailedException {
-        Future<Class> clazz = classMap.get(script);
-
-        long start = System.currentTimeMillis();
         try {
-            if (clazz != null) {
-                return clazz.get();
-            }
-
-            clazz = CompletableFuture.supplyAsync(() -> loader.parseClass(script, generateScriptName()));
-            classMap.put(script, clazz);
-            return clazz.get();
-
-        } catch (Exception e) {
-            if (e.getCause() instanceof CompilationFailedException) {
-                long finish = System.currentTimeMillis();
-                log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e.getCause());
-                throw (CompilationFailedException) e.getCause();
-            } else {
-                throw new AssertionError("Unexpected exception when compiling script", e);
-            }
-        } finally {
-            long time = System.currentTimeMillis() - start;
-            if (time > 5000) {
-                //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
-                //Scripts with a large numbers of parameters often trigger this and should be avoided.
-                log.warn("Script compilation {} took {}ms", script, time);
-            } else {
-                log.debug("Script compilation {} took {}ms", script, time);
-            }
+            return classMap.get(script).get();
+        } catch (ExecutionException e) {
+            throw ((CompilationFailedException)e.getCause());
+        } catch (InterruptedException e) {
+            //This should never happen as the future should completed before it is returned to the us.
+            throw new AssertionError();
         }
 
+
     }
 
     boolean isCached(final String script) {
-        return classMap.get(script) != null;
+        return classMap.getIfPresent(script) != null;
     }
 
     Object eval(final Class scriptClass, final ScriptContext context) throws ScriptException {


[16/20] tinkerpop git commit: TINKERPOP-1644 Fixed spelling errors

Posted by sp...@apache.org.
TINKERPOP-1644 Fixed spelling errors


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

Branch: refs/heads/master
Commit: 85c53305f83b9915538289bcb7de596620b76d6c
Parents: 33db1a3
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Mar 14 12:30:14 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Mar 14 12:30:14 2017 -0400

----------------------------------------------------------------------
 docs/src/reference/gremlin-applications.asciidoc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/85c53305/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 37244e0..884ce04 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -1560,10 +1560,10 @@ and standard deviation evaluation times, as well as the 75th, 95th, 98th, 99th a
 * `op.traversal` - the number of `Traveral` executions, mean rate, 1, 5, and 15 minute rates, minimum, maximum, median,
 mean, and standard deviation evaluation times, as well as the 75th, 95th, 98th, 99th and 99.9th percentile evaluation
 times.
-* `engine-name.session.session-id.*` - metrics related to different `GremlinScriptEngine` instanc configured for
+* `engine-name.session.session-id.*` - metrics related to different `GremlinScriptEngine` instances configured for
 session-based requests where "engine-name" will be the actual name of the engine, such as "gremlin-groovy" and
 "session-id" will be the identifier for the session itself.
-* `engine-name.sessionless.*` - metrics related to different `GremlinScriptEngine` instanc configured for sessionless
+* `engine-name.sessionless.*` - metrics related to different `GremlinScriptEngine` instances configured for sessionless
 requests where "engine-name" will be the actual name of the engine, such as "gremlin-groovy".
 
 Best Practices


[20/20] tinkerpop git commit: Merge branch 'tp32'

Posted by sp...@apache.org.
Merge branch 'tp32'

Conflicts:
	docs/src/reference/gremlin-applications.asciidoc
	gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
	gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
	gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java


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

Branch: refs/heads/master
Commit: ef10d8f2b8488b6a8fbb66f4ea10cb5efabb5b97
Parents: b5bd36b d7c2a22
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 15 12:02:45 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Mar 15 12:02:45 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   7 +
 .../src/reference/gremlin-applications.asciidoc |   6 +
 .../upgrade/release-3.2.x-incubating.asciidoc   |  10 +
 gremlin-groovy/pom.xml                          |   5 +
 .../jsr223/CompilationOptionsCustomizer.java    |  39 ++++
 .../jsr223/GremlinGroovyScriptEngine.java       | 205 +++++++++++++++++--
 .../jsr223/GroovyCompilerGremlinPlugin.java     |  13 ++
 ...roovyScriptEngineCompilationOptionsTest.java |  56 +++++
 .../jsr223/GremlinGroovyScriptEngineTest.java   |  70 ++++++-
 .../jsr223/GroovyCompilerGremlinPluginTest.java |  25 ++-
 gremlin-server/pom.xml                          |   5 -
 .../gremlin/server/op/session/Session.java      |  18 ++
 .../gremlin/server/util/MetricManager.java      |  80 +++++++-
 .../server/util/ServerGremlinExecutor.java      |   7 +
 14 files changed, 509 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --cc docs/src/reference/gremlin-applications.asciidoc
index 6e1ea57,3a2c446..9932442
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@@ -1453,17 -1335,14 +1453,18 @@@ The `GroovyCompilerGremlinPlugin` has 
  [width="100%",cols="3,10a",options="header"]
  |=========================================================
  |Customizer |Description
 -|`CompileStaticCustomizerProvider` |Applies `CompileStatic` annotations to incoming scripts thus removing dynamic dispatch. More information about static compilation can be found in the link:http://docs.groovy-lang.org/latest/html/documentation/#_static_compilation[Groovy Documentation].  It is possible to configure this `CustomizerProvider` by specifying a comma separated list of link:http://docs.groovy-lang.org/latest/html/documentation/#Typecheckingextensions-Workingwithextensions[type checking extensions] that can have the effect of securing calls to various methods.
 -|`CompilationOptionsCustomizerProvider` |The amount of time a script is allowed to compile before a warning message is sent to the logs.
 -|`ConfigurationCustomizerProvider` |Allows configuration of the Groovy `CompilerConfiguration` object by taking a `Map` of key/value pairs where the "key" is a property to set on the `CompilerConfiguration`.
 -|`ThreadInterruptCustomizerProvider` |Injects checks for thread interruption, thus allowing the thread to potentially respect calls to `Thread.interrupt()`
 -|`TimedInterruptCustomizerProvider` |Injects checks into loops to interrupt them if they exceed the configured timeout in milliseconds.
 -|`TypeCheckedCustomizerProvider` |Similar to the above mentioned, `CompileStaticCustomizerProvider`, the `TypeCheckedCustomizerProvider` injects `TypeChecked` annotations to incoming scripts.  More information on the nature of this annotation can be found in the link:http://docs.groovy-lang.org/latest/html/documentation/#_the_code_typechecked_code_annotation[Groovy Documentation].  It too takes a comma separated list of link:http://docs.groovy-lang.org/latest/html/documentation/#Typecheckingextensions-Workingwithextensions[type checking extensions].
 +|`compilation` |Allows for three configurations: `COMPILE_STATIC`, `TYPE_CHECKED` or `NONE` (default). When configured with `COMPILE_STATIC` or `TYPE_CHECKED` it applies `CompileStatic` or `TypeChecked` annotations (respectively) to incoming scripts thus removing dynamic dispatch. More information about static compilation can be found link:http://docs.groovy-lang.org/latest/html/documentation/#_static_compilation[here] and additional information on `TypeChecked` usage can be found link:http://docs.groovy-lang.org/latest/html/documentation/#_the_code_typechecked_code_annotation[here].
 +|`compilerConfigurationOptions` |Allows configuration of the Groovy `CompilerConfiguration` object by taking a `Map` of key/value pairs where the "key" is a property to set on the `CompilerConfiguration`.
 +|`enableThreadInterrupt` |Injects checks for thread interruption, thus allowing the thread to potentially respect calls to `Thread.interrupt()`
++|`expectedCompilationTime` |The amount of time in milliseconds a script is allowed to compile before a warning message is sent to the logs.
 +|`extensions` | This setting is for use when `compilation` is configured with `COMPILE_STATIC` or `TYPE_CHECKED` and accepts a comma separated list of link:http://docs.groovy-lang.org/latest/html/documentation/#Typecheckingextensions-Workingwithextensions[type checking extensions] that can have the effect of securing calls to various methods.
 +|`timedInterrupt` |Injects checks into loops to interrupt them if they exceed the configured timeout in milliseconds.
  |=========================================================
  
 +NOTE: Consult the latest link:http://docs.groovy-lang.org/latest/html/documentation/#_typing[Groovy Documentation]
 +for information on the differences. It is important to understand the impact that these configuration will have on
 +submitted scripts before enabling this feature.
 +
  To provide some basic out-of-the-box protections against troublesome scripts, the following configuration can be used:
  
  [source,yaml]
@@@ -1671,63 -1562,12 +1672,68 @@@ and standard deviation evaluation times
  * `op.traversal` - the number of `Traveral` executions, mean rate, 1, 5, and 15 minute rates, minimum, maximum, median,
  mean, and standard deviation evaluation times, as well as the 75th, 95th, 98th, 99th and 99.9th percentile evaluation
  times.
+ * `engine-name.session.session-id.*` - metrics related to different `GremlinScriptEngine` instances configured for
+ session-based requests where "engine-name" will be the actual name of the engine, such as "gremlin-groovy" and
+ "session-id" will be the identifier for the session itself.
+ * `engine-name.sessionless.*` - metrics related to different `GremlinScriptEngine` instances configured for sessionless
+ requests where "engine-name" will be the actual name of the engine, such as "gremlin-groovy".
  
 +As A Service
 +^^^^^^^^^^^^
 +
 +Gremlin server can be configured to run as a service.
 +
 +Init.d (SysV)
 ++++++++++++++
 +
 +Link `bin/gremlin-server.sh` to `init.d`
 +Be sure to set RUNAS to the service user in `bin/gremlin-server.conf`
 +
 +[source,bash]
 +----
 +# Install
 +ln -s /path/to/apache-tinkerpop-gremlin-server-x.y.z/bin/gremlin-server.sh /etc/init.d/gremlin-server
 +
 +# Systems with chkconfig/service. E.g. Fedora, Red Hat
 +chkconfig --add gremlin-server
 +
 +# Start
 +service gremlin-server start
 +
 +# Or call directly
 +/etc/init.d/gremlin-server restart
 +
 +----
 +
 +Systemd
 ++++++++
 +
 +To install, copy the service template below to /etc/systemd/system/gremlin.service
 +and update the paths `/path/to/apache-tinkerpop-gremlin-server` with the actual install path of Gremlin Server.
 +
 +[source,bash]
 +----
 +[Unit]
 +Description=Apache TinkerPop Gremlin Server daemon
 +Documentation=http://tinkerpop.apache.org/
 +After=network.target
 +
 +[Service]
 +Type=forking
 +ExecStart=/path/to/apache-tinkerpop-gremlin-server/bin/gremlin-server.sh start
 +ExecStop=/path/to/apache-tinkerpop-gremlin-server/bin/gremlin-server.sh stop
 +PIDFile=/path/to/apache-tinkerpop-gremlin-server/run/gremlin.pid
 +
 +[Install]
 +WantedBy=multi-user.target
 +----
 +
 +
 +Enable the service with `systemctl enable gremlin-server`
 +
 +Start the service with `systemctl start gremlin-server`
 +
 +
  Best Practices
  ~~~~~~~~~~~~~~
  

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/pom.xml
----------------------------------------------------------------------
diff --cc gremlin-groovy/pom.xml
index 75b21a5,474b458..fdf6caf
--- a/gremlin-groovy/pom.xml
+++ b/gremlin-groovy/pom.xml
@@@ -70,14 -70,13 +70,19 @@@ limitations under the License
              <artifactId>jbcrypt</artifactId>
              <version>0.4</version>
          </dependency>
+         <dependency>
+             <groupId>com.github.ben-manes.caffeine</groupId>
+             <artifactId>caffeine</artifactId>
+             <version>2.3.1</version>
+         </dependency>
          <!-- TEST -->
          <dependency>
 +            <groupId>org.apache.tinkerpop</groupId>
 +            <artifactId>tinkergraph-gremlin</artifactId>
 +            <version>${project.version}</version>
 +            <scope>test</scope>
 +        </dependency>
 +        <dependency>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-log4j12</artifactId>
              <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --cc gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 0ac5582,4b27180..9d232d8
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@@ -18,6 -18,10 +18,9 @@@
   */
  package org.apache.tinkerpop.gremlin.groovy.jsr223;
  
+ import com.github.benmanes.caffeine.cache.CacheLoader;
+ import com.github.benmanes.caffeine.cache.Caffeine;
+ import com.github.benmanes.caffeine.cache.LoadingCache;
 -import groovy.grape.Grape;
  import groovy.lang.Binding;
  import groovy.lang.Closure;
  import groovy.lang.DelegatingMetaClass;
@@@ -80,8 -101,9 +89,9 @@@ import java.util.stream.Collectors
   * @see org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor
   */
  public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
 -        implements DependencyManager, AutoCloseable, GremlinScriptEngine {
 +        implements AutoCloseable, GremlinScriptEngine {
  
+     private static final Logger log = LoggerFactory.getLogger(GremlinGroovyScriptEngine.class);
      /**
       * An "internal" key for sandboxing the script engine - technically not for public use.
       */
@@@ -167,10 -233,15 +221,11 @@@
      private final ImportGroovyCustomizer importGroovyCustomizer;
      private final List<GroovyCustomizer> groovyCustomizers;
  
 -    private final Set<Artifact> artifactsToUse = new HashSet<>();
      private final boolean interpreterModeEnabled;
+     private final long expectedCompilationTime;
  
      /**
 -     * Creates a new instance using the {@link DefaultImportCustomizerProvider}.
 +     * Creates a new instance using no {@link Customizer}.
       */
      public GremlinGroovyScriptEngine() {
          this(new Customizer[0]);
@@@ -249,8 -483,11 +310,8 @@@
  
          // must clear the local cache here because the classloader has been reset.  therefore, classes previously
          // referenced before that might not have evaluated might cleanly evaluate now.
-         classMap.clear();
+         classMap.invalidateAll();
          globalClosures.clear();
 -
 -        final Set<Artifact> toReuse = new HashSet<>(artifactsToUse);
 -        toReuse.forEach(this::use);
      }
  
      /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
----------------------------------------------------------------------
diff --cc gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
index 0000000,b87d0ac..b1ec3e5
mode 000000,100644..100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
@@@ -1,0 -1,80 +1,56 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one
+  * or more contributor license agreements.  See the NOTICE file
+  * distributed with this work for additional information
+  * regarding copyright ownership.  The ASF licenses this file
+  * to you 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.apache.tinkerpop.gremlin.groovy.jsr223;
+ 
 -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompilationOptionsCustomizerProvider;
+ import org.junit.Test;
+ 
+ import javax.script.Bindings;
+ import javax.script.SimpleBindings;
+ 
+ import static org.junit.Assert.assertEquals;
+ 
+ /**
+  * @author Stephen Mallette (http://stephen.genoprime.com)
+  */
+ public class GremlinGroovyScriptEngineCompilationOptionsTest {
 -    @Test
 -    public void shouldRegisterLongCompilationDeprecated() throws Exception {
 -        final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CompilationOptionsCustomizerProvider(10));
 -
 -        final int numberOfParameters = 3000;
 -        final Bindings b = new SimpleBindings();
 -
 -        // generate a script that takes a long time to compile
 -        String script = "x = 0";
 -        for (int ix = 0; ix < numberOfParameters; ix++) {
 -            if (ix > 0 && ix % 100 == 0) {
 -                script = script + ";" + System.lineSeparator() + "x = x";
 -            }
 -            script = script + " + x" + ix;
 -            b.put("x" + ix, ix);
 -        }
 -
 -        assertEquals(0, engine.getClassCacheLongRunCompilationCount());
 -
 -        engine.eval(script, b);
 -
 -        assertEquals(1, engine.getClassCacheLongRunCompilationCount());
 -    }
+ 
+     @Test
+     public void shouldRegisterLongCompilation() throws Exception {
+         final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CompilationOptionsCustomizer(10));
+ 
+         final int numberOfParameters = 3000;
+         final Bindings b = new SimpleBindings();
+ 
+         // generate a script that takes a long time to compile
+         String script = "x = 0";
+         for (int ix = 0; ix < numberOfParameters; ix++) {
+             if (ix > 0 && ix % 100 == 0) {
+                 script = script + ";" + System.lineSeparator() + "x = x";
+             }
+             script = script + " + x" + ix;
+             b.put("x" + ix, ix);
+         }
+ 
+         assertEquals(0, engine.getClassCacheLongRunCompilationCount());
+ 
+         engine.eval(script, b);
+ 
+         assertEquals(1, engine.getClassCacheLongRunCompilationCount());
+     }
+ }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-server/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
index 62a08cb,6961339..3a3c836
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
@@@ -18,7 -18,11 +18,10 @@@
   */
  package org.apache.tinkerpop.gremlin.server.op.session;
  
+ import com.codahale.metrics.Metric;
+ import com.codahale.metrics.MetricFilter;
  import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
 -import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines;
+ import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
  import org.apache.tinkerpop.gremlin.server.Context;
  import org.apache.tinkerpop.gremlin.server.GraphManager;
  import org.apache.tinkerpop.gremlin.server.Settings;
@@@ -90,6 -98,15 +97,8 @@@ public class Session 
                  SessionOpProcessor.CONFIG_PER_GRAPH_CLOSE_TIMEOUT, SessionOpProcessor.DEFAULT_PER_GRAPH_CLOSE_TIMEOUT).toString());
  
          this.gremlinExecutor = initializeGremlinExecutor().create();
+ 
 -        settings.scriptEngines.keySet().forEach(engineName -> {
 -            try {
 -                gremlinExecutor.eval("1+1", engineName, Collections.emptyMap()).join();
 -                registerMetrics(engineName);
 -            } catch (Exception ex) {
 -                logger.warn(String.format("Could not initialize {} ScriptEngine as script could not be evaluated - %s", engineName), ex);
 -            }
 -        });
++        settings.scriptEngines.keySet().forEach(this::registerMetrics);
      }
  
      public GremlinExecutor getGremlinExecutor() {
@@@ -235,4 -263,12 +248,9 @@@
  
          return gremlinExecutorBuilder;
      }
+ 
+     private void registerMetrics(final String engineName) {
 -        final ScriptEngines scriptEngines = gremlinExecutor.getScriptEngines();
 -        final GremlinScriptEngine engine = null == scriptEngines ?
 -                gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
 -                scriptEngines.getEngineByName(engineName);
++        final GremlinScriptEngine engine = gremlinExecutor.getScriptEngineManager().getEngineByName(engineName);
+         MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, engineName, "session", session, "class-cache");
+     }
  }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index 116d627,e3c0cae..6bf8095
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@@ -18,7 -18,11 +18,8 @@@
   */
  package org.apache.tinkerpop.gremlin.server.util;
  
 -import com.codahale.metrics.Gauge;
  import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
 -import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines;
 -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+ import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
  import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
  import org.apache.tinkerpop.gremlin.server.Channelizer;
  import org.apache.tinkerpop.gremlin.server.GraphManager;
@@@ -171,6 -186,14 +173,11 @@@ public class ServerGremlinExecutor<T ex
                  .collect(Collectors.toList());
      }
  
+     private void registerMetrics(final String engineName) {
 -        final ScriptEngines scriptEngines = gremlinExecutor.getScriptEngines();
 -        final GremlinScriptEngine engine = null == scriptEngines ?
 -                gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
 -                scriptEngines.getEngineByName(engineName);
++        final GremlinScriptEngine engine = gremlinExecutor.getScriptEngineManager().getEngineByName(engineName);
+         MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, engineName, "sessionless", "class-cache");
+     }
+ 
      public void addHostOption(final String key, final Object value) {
          hostOptions.put(key, value);
      }


[02/20] tinkerpop git commit: TINKERPOP-1644 Provided configuration options for GremlinGroovyScriptEngine

Posted by sp...@apache.org.
TINKERPOP-1644 Provided configuration options for GremlinGroovyScriptEngine

Introduced new customizers to pass in configuration options to the GremlinGroovyScriptEngine.


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

Branch: refs/heads/master
Commit: 4bdeac4b796b38fb14d1be763e03cc837b57d3d7
Parents: de1d58a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 16:13:06 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:36 2017 -0500

----------------------------------------------------------------------
 .../jsr223/CompilationOptionsCustomizer.java    | 39 ++++++++++
 .../jsr223/GremlinGroovyScriptEngine.java       | 36 +++++++--
 .../jsr223/GroovyCompilerGremlinPlugin.java     | 13 ++++
 .../CompilationOptionsCustomizerProvider.java   | 48 ++++++++++++
 ...roovyScriptEngineCompilationOptionsTest.java | 80 ++++++++++++++++++++
 .../jsr223/GroovyCompilerGremlinPluginTest.java | 24 ++++--
 6 files changed, 225 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4bdeac4b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java
new file mode 100644
index 0000000..2a22eb3
--- /dev/null
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.tinkerpop.gremlin.groovy.jsr223;
+
+import org.apache.tinkerpop.gremlin.jsr223.Customizer;
+
+/**
+ * Provides some custom compilation options to the {@link GremlinGroovyScriptEngine}.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+class CompilationOptionsCustomizer implements Customizer {
+
+    private final int expectedCompilationTime;
+
+    public CompilationOptionsCustomizer(final int expectedCompilationTime) {
+        this.expectedCompilationTime = expectedCompilationTime;
+    }
+
+    public int getExpectedCompilationTime() {
+        return expectedCompilationTime;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4bdeac4b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 42d954a..5168130 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -35,6 +35,7 @@ import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.ImportCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompilationOptionsCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ConfigurationCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader;
@@ -80,11 +81,11 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.regex.Pattern;
@@ -125,7 +126,6 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
      */
     public static final String REFERENCE_TYPE_PHANTOM = "phantom";
 
-
     /**
      * A value to the {@link #KEY_REFERENCE_TYPE} that marks the script as one that can be garbage collected
      * even when memory is abundant.
@@ -178,26 +178,26 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
                     throw e;
                 } finally {
                     final long time = System.currentTimeMillis() - start;
-                    if (time > 5000) {
+                    if (time > expectedCompilationTime) {
                         //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong.
                         //Scripts with a large numbers of parameters often trigger this and should be avoided.
                         log.warn("Script compilation {} took {}ms", script, time);
+                        longRunCompilationCount.incrementAndGet();
                     } else {
                         log.debug("Script compilation {} took {}ms", script, time);
                     }
                 }
             }, Runnable::run);
         }
-
     });
 
     /**
      * Global closures map - this is used to simulate a single global functions namespace
      */
-    private ManagedConcurrentValueMap<String, Closure> globalClosures = new ManagedConcurrentValueMap<>(ReferenceBundle.getHardBundle());
-
+    private final ManagedConcurrentValueMap<String, Closure> globalClosures = new ManagedConcurrentValueMap<>(ReferenceBundle.getHardBundle());
 
-    private AtomicLong counter = new AtomicLong(0L);
+    private final AtomicLong counter = new AtomicLong(0L);
+    private final AtomicLong longRunCompilationCount = new AtomicLong(0L);
 
     /**
      * The list of loaded plugins for the console.
@@ -219,6 +219,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
 
     private final Set<Artifact> artifactsToUse = new HashSet<>();
     private final boolean interpreterModeEnabled;
+    private final int expectedCompilationTime;
 
     /**
      * Creates a new instance using the {@link DefaultImportCustomizerProvider}.
@@ -255,6 +256,12 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
                 .map(p -> ((GroovyCustomizer) p))
                 .collect(Collectors.toList());
 
+        final Optional<CompilationOptionsCustomizer> compilationOptionsCustomizerProvider = listOfCustomizers.stream()
+                .filter(p -> p instanceof CompilationOptionsCustomizer)
+                .map(p -> (CompilationOptionsCustomizer) p).findFirst();
+        expectedCompilationTime = compilationOptionsCustomizerProvider.isPresent() ?
+                compilationOptionsCustomizerProvider.get().getExpectedCompilationTime() : 5000;
+
         // determine if interpreter mode should be enabled
         interpreterModeEnabled = groovyCustomizers.stream()
                 .anyMatch(p -> p.getClass().equals(InterpreterModeGroovyCustomizer.class));
@@ -286,9 +293,15 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         interpreterModeEnabled = providers.stream()
                 .anyMatch(p -> p.getClass().equals(InterpreterModeCustomizerProvider.class));
 
+        final Optional<CompilationOptionsCustomizerProvider> compilationOptionsCustomizerProvider = providers.stream()
+                .filter(p -> p instanceof CompilationOptionsCustomizerProvider)
+                .map(p -> (CompilationOptionsCustomizerProvider) p).findFirst();
+        expectedCompilationTime = compilationOptionsCustomizerProvider.isPresent() ?
+            compilationOptionsCustomizerProvider.get().getExpectedCompilationTime() : 5000;
+
         // remove used providers as the rest will be applied directly
         customizerProviders = providers.stream()
-                .filter(p -> p != null && !(p instanceof ImportCustomizerProvider))
+                .filter(p -> p != null && !(p instanceof ImportCustomizerProvider) && !(p instanceof CompilationOptionsCustomizerProvider))
                 .collect(Collectors.toList());
 
         // groovy customizers are not used here - set to empty list so that the customizerProviders get used
@@ -565,6 +578,13 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         return makeInterface(thiz, clazz);
     }
 
+    /**
+     * Gets the number of compilations that extended beyond the {@link #expectedCompilationTime}.
+     */
+    public long getLongRunCompilationCount() {
+        return longRunCompilationCount.longValue();
+    }
+
     Class getScriptClass(final String script) throws CompilationFailedException {
         try {
             return classMap.get(script).get();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4bdeac4b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java
index 71f5dc7..5680a4f 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPlugin.java
@@ -59,9 +59,19 @@ public class GroovyCompilerGremlinPlugin extends AbstractGremlinPlugin {
         private long timeInMillis = 0;
         private Compilation compilation = Compilation.NONE;
         private String extensions = null;
+        private int expectedCompilationTime = 5000;
 
         private Map<String,Object> keyValues = Collections.emptyMap();
 
+        /**
+         * If the time it takes to compile a script exceeds the specified time then a warning is written to the logs.
+         * Defaults to 5000ms.
+         */
+        public Builder expectedCompilationTime(final int timeInMillis) {
+            this.expectedCompilationTime = timeInMillis;
+            return this;
+        }
+
         public Builder enableInterpreterMode(final boolean interpreterMode) {
             this.interpreterMode = interpreterMode;
             return this;
@@ -111,6 +121,9 @@ public class GroovyCompilerGremlinPlugin extends AbstractGremlinPlugin {
             if (timeInMillis > 0)
                 list.add(new TimedInterruptGroovyCustomizer(timeInMillis));
 
+            if (expectedCompilationTime > 0)
+                list.add(new CompilationOptionsCustomizer(expectedCompilationTime));
+
             if (compilation == Compilation.COMPILE_STATIC)
                 list.add(new CompileStaticGroovyCustomizer(extensions));
             else if (compilation == Compilation.TYPE_CHECKED)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4bdeac4b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
new file mode 100644
index 0000000..0475511
--- /dev/null
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.tinkerpop.gremlin.groovy.jsr223.customizer;
+
+import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+import org.codehaus.groovy.control.customizers.CompilationCustomizer;
+
+/**
+ * Provides compilation configuration options to the {@link GremlinGroovyScriptEngine}.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ * @deprecated As of release 3.2.5, not replaced by a public class.
+ */
+@Deprecated
+public class CompilationOptionsCustomizerProvider implements CompilerCustomizerProvider {
+
+    private final int expectedCompilationTime;
+
+    public CompilationOptionsCustomizerProvider(final int expectedCompilationTime) {
+        this.expectedCompilationTime = expectedCompilationTime;
+    }
+
+    public int getExpectedCompilationTime() {
+        return expectedCompilationTime;
+    }
+
+    @Override
+    public CompilationCustomizer create() {
+        throw new UnsupportedOperationException("This is a marker implementation that does not create a CompilationCustomizer instance");
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4bdeac4b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
new file mode 100644
index 0000000..f5dd9c5
--- /dev/null
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.tinkerpop.gremlin.groovy.jsr223;
+
+import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompilationOptionsCustomizerProvider;
+import org.junit.Test;
+
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GremlinGroovyScriptEngineCompilationOptionsTest {
+    @Test
+    public void shouldRegisterLongCompilationDeprecated() throws Exception {
+        final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CompilationOptionsCustomizerProvider(10));
+
+        final int numberOfParameters = 3000;
+        final Bindings b = new SimpleBindings();
+
+        // generate a script that takes a long time to compile
+        String script = "x = 0";
+        for (int ix = 0; ix < numberOfParameters; ix++) {
+            if (ix > 0 && ix % 100 == 0) {
+                script = script + ";" + System.lineSeparator() + "x = x";
+            }
+            script = script + " + x" + ix;
+            b.put("x" + ix, ix);
+        }
+
+        assertEquals(0, engine.getLongRunCompilationCount());
+
+        engine.eval(script, b);
+
+        assertEquals(1, engine.getLongRunCompilationCount());
+    }
+
+    @Test
+    public void shouldRegisterLongCompilation() throws Exception {
+        final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CompilationOptionsCustomizer(10));
+
+        final int numberOfParameters = 3000;
+        final Bindings b = new SimpleBindings();
+
+        // generate a script that takes a long time to compile
+        String script = "x = 0";
+        for (int ix = 0; ix < numberOfParameters; ix++) {
+            if (ix > 0 && ix % 100 == 0) {
+                script = script + ";" + System.lineSeparator() + "x = x";
+            }
+            script = script + " + x" + ix;
+            b.put("x" + ix, ix);
+        }
+
+        assertEquals(0, engine.getLongRunCompilationCount());
+
+        engine.eval(script, b);
+
+        assertEquals(1, engine.getLongRunCompilationCount());
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4bdeac4b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
index f795fa7..bacfc90 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java
@@ -18,12 +18,6 @@
  */
 package org.apache.tinkerpop.gremlin.groovy.jsr223;
 
-import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ConfigurationCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ThreadInterruptCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TypeCheckedCustomizerProvider;
 import org.apache.tinkerpop.gremlin.jsr223.Customizer;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.junit.Test;
@@ -54,6 +48,7 @@ public class GroovyCompilerGremlinPluginTest {
     @Test
     public void shouldConfigureWithCompileStatic() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
+                expectedCompilationTime(0).
                 compilation(Compilation.COMPILE_STATIC).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
@@ -64,6 +59,7 @@ public class GroovyCompilerGremlinPluginTest {
     @Test
     public void shouldConfigureWithTypeChecked() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
+                expectedCompilationTime(0).
                 compilation(Compilation.TYPE_CHECKED).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
@@ -76,6 +72,7 @@ public class GroovyCompilerGremlinPluginTest {
         final Map<String,Object> conf = new HashMap<>();
         conf.put("Debug", true);
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
+                expectedCompilationTime(0).
                 compilerConfigurationOptions(conf).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
@@ -94,6 +91,7 @@ public class GroovyCompilerGremlinPluginTest {
     @Test
     public void shouldConfigureWithInterpreterMode() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
+                expectedCompilationTime(0).
                 enableInterpreterMode(true).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
@@ -104,6 +102,7 @@ public class GroovyCompilerGremlinPluginTest {
     @Test
     public void shouldConfigureWithThreadInterrupt() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
+                expectedCompilationTime(0).
                 enableThreadInterrupt(true).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
@@ -114,6 +113,7 @@ public class GroovyCompilerGremlinPluginTest {
     @Test
     public void shouldConfigureWithTimedInterrupt() {
         final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
+                expectedCompilationTime(0).
                 timedInterrupt(60000).create();
         final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
         assertThat(customizers.isPresent(), is(true));
@@ -121,8 +121,18 @@ public class GroovyCompilerGremlinPluginTest {
         assertThat(customizers.get()[0], instanceOf(TimedInterruptGroovyCustomizer.class));
     }
 
+    @Test
+    public void shouldConfigureWithCompilationOptions() {
+        final GroovyCompilerGremlinPlugin plugin = GroovyCompilerGremlinPlugin.build().
+                expectedCompilationTime(30000).create();
+        final Optional<Customizer[]> customizers = plugin.getCustomizers("gremlin-groovy");
+        assertThat(customizers.isPresent(), is(true));
+        assertEquals(1, customizers.get().length);
+        assertThat(customizers.get()[0], instanceOf(CompilationOptionsCustomizer.class));
+    }
+
     @Test(expected = IllegalStateException.class)
     public void shouldNotConfigureIfNoSettingsAreSupplied() {
-        GroovyCompilerGremlinPlugin.build().create();
+        GroovyCompilerGremlinPlugin.build().expectedCompilationTime(0).create();
     }
 }


[10/20] tinkerpop git commit: TINKERPOP-1644 Made the "counter" in GremlinGroovyScriptEngine static

Posted by sp...@apache.org.
TINKERPOP-1644 Made the "counter" in GremlinGroovyScriptEngine static

It seems that this field should be static and shared across all instances as the script name seems to share space with other GroovyClassLoaders. Not sure what would happen in the case of collision, but there doesn't seem to be much harm in ensuring better uniqueness. This counter wasn't used for tracking the number of scripts actually processed or anything so it should be ok to make this change without fear of breaking anything.


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

Branch: refs/heads/master
Commit: a06072b0502f9b42fee4c68dba554b4991406c36
Parents: b29ba12
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 16:17:40 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 10 11:12:37 2017 -0500

----------------------------------------------------------------------
 .../groovy/jsr223/GremlinGroovyScriptEngine.java        | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a06072b0/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 5168130..3bcb06c 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -196,7 +196,15 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
      */
     private final ManagedConcurrentValueMap<String, Closure> globalClosures = new ManagedConcurrentValueMap<>(ReferenceBundle.getHardBundle());
 
-    private final AtomicLong counter = new AtomicLong(0L);
+    /**
+     * Ensures unique script names across all instances.
+     */
+    private final static AtomicLong scriptNameCounter = new AtomicLong(0L);
+
+    /**
+     * A counter for the instance that tracks the number of warnings issued during script compilations that exceeded
+     * the {@link #expectedCompilationTime}.
+     */
     private final AtomicLong longRunCompilationCount = new AtomicLong(0L);
 
     /**
@@ -799,7 +807,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     }
 
     private synchronized String generateScriptName() {
-        return SCRIPT + counter.incrementAndGet() + DOT_GROOVY;
+        return SCRIPT + scriptNameCounter.incrementAndGet() + DOT_GROOVY;
     }
 
     @SuppressWarnings("unchecked")


[17/20] tinkerpop git commit: TINKERPOP-1644 Changed time settings to Long values.

Posted by sp...@apache.org.
TINKERPOP-1644 Changed time settings to Long values.

Using long is consistent with other customizer instances.


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

Branch: refs/heads/master
Commit: 7fced963db5b73b4bb8e943f7db02cf2a491cd12
Parents: 85c5330
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Mar 14 12:30:26 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Mar 14 12:30:26 2017 -0400

----------------------------------------------------------------------
 .../groovy/jsr223/CompilationOptionsCustomizer.java     |  6 +++---
 .../groovy/jsr223/GremlinGroovyScriptEngine.java        |  2 +-
 .../CompilationOptionsCustomizerProvider.java           | 12 ++++++++----
 3 files changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7fced963/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java
index 2a22eb3..de39b62 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/CompilationOptionsCustomizer.java
@@ -27,13 +27,13 @@ import org.apache.tinkerpop.gremlin.jsr223.Customizer;
  */
 class CompilationOptionsCustomizer implements Customizer {
 
-    private final int expectedCompilationTime;
+    private final long expectedCompilationTime;
 
-    public CompilationOptionsCustomizer(final int expectedCompilationTime) {
+    public CompilationOptionsCustomizer(final long expectedCompilationTime) {
         this.expectedCompilationTime = expectedCompilationTime;
     }
 
-    public int getExpectedCompilationTime() {
+    public long getExpectedCompilationTime() {
         return expectedCompilationTime;
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7fced963/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 0ed8d84..4b27180 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -238,7 +238,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
 
     private final Set<Artifact> artifactsToUse = new HashSet<>();
     private final boolean interpreterModeEnabled;
-    private final int expectedCompilationTime;
+    private final long expectedCompilationTime;
 
     /**
      * Creates a new instance using the {@link DefaultImportCustomizerProvider}.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7fced963/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
index 0475511..00a20f1 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/CompilationOptionsCustomizerProvider.java
@@ -31,13 +31,17 @@ import org.codehaus.groovy.control.customizers.CompilationCustomizer;
 @Deprecated
 public class CompilationOptionsCustomizerProvider implements CompilerCustomizerProvider {
 
-    private final int expectedCompilationTime;
+    private final long expectedCompilationTime;
 
-    public CompilationOptionsCustomizerProvider(final int expectedCompilationTime) {
-        this.expectedCompilationTime = expectedCompilationTime;
+    public CompilationOptionsCustomizerProvider(final Integer expectedCompilationTime) {
+        this.expectedCompilationTime = expectedCompilationTime.longValue();
     }
 
-    public int getExpectedCompilationTime() {
+    public CompilationOptionsCustomizerProvider(final Long expectedCompilationTime) {
+        this.expectedCompilationTime = expectedCompilationTime.intValue();
+    }
+
+    public long getExpectedCompilationTime() {
         return expectedCompilationTime;
     }