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/09 18:16:21 UTC
[01/15] tinkerpop git commit: TINKERPOP-1645 Bump to groovy 2.4.9
[Forced Update!]
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1644 ab3cc8450 -> dc87eb526 (forced update)
TINKERPOP-1645 Bump to groovy 2.4.9
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cde8b316
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cde8b316
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cde8b316
Branch: refs/heads/TINKERPOP-1644
Commit: cde8b316e2cfdc7d8a7d1d3456d68d0f3a5d9828
Parents: 6a20df2
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Mar 6 08:54:18 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Mar 6 08:54:18 2017 -0500
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cde8b316/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5d2184f..23f31f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,7 +127,7 @@ limitations under the License.
</scm>
<properties>
<commons.configuration.version>1.10</commons.configuration.version>
- <groovy.version>2.4.8</groovy.version>
+ <groovy.version>2.4.9</groovy.version>
<junit.version>4.12</junit.version>
<metrics.version>3.0.2</metrics.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
[07/15] 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/6ebfd2b2
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6ebfd2b2
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6ebfd2b2
Branch: refs/heads/TINKERPOP-1644
Commit: 6ebfd2b23e3b55c1388b42852929185c7d3dc234
Parents: 07cac66
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 10:30:17 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 2017 -0500
----------------------------------------------------------------------
CHANGELOG.asciidoc | 6 +-
.../jsr223/GremlinGroovyScriptEngine.java | 122 ++++++++++++++++++-
...roovyScriptEngineCompilationOptionsTest.java | 8 +-
.../jsr223/GremlinGroovyScriptEngineTest.java | 70 ++++++++++-
4 files changed, 193 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ebfd2b2/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 0ac18bc..f59eac3 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,11 +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`.
-* 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.
+* Improved script compilation in `GremlinGroovyScriptEngine to use better caching, log long compile times and prevent failed compilations from recompiling on future requests.
* 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.
* Deprecated `CustomizerProvider` infrastructure.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ebfd2b2/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/6ebfd2b2/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/6ebfd2b2/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
[08/15] tinkerpop git commit: TINKERPOP-1644 Updated changelog
Posted by sp...@apache.org.
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/5dc7c998
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5dc7c998
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5dc7c998
Branch: refs/heads/TINKERPOP-1644
Commit: 5dc7c998ce767e6a6e75b894f8ac7694ca1f55aa
Parents: 73e9e9f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 16:15:27 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 2017 -0500
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5dc7c998/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f14412e..0ac18bc 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.
[13/15] 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/d9699005
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d9699005
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d9699005
Branch: refs/heads/TINKERPOP-1644
Commit: d96990057adfaae6714cb2f2f6ec80d702ece058
Parents: 6ebfd2b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 12:25:35 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 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/d9699005/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f59eac3..752cf43 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.
* Split `ComputerVerificationStrategy` into two strategies: `ComputerVerificationStrategy` and `ComputerFinalizationStrategy`.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d9699005/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/d9699005/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/d9699005/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/d9699005/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);
}
[02/15] tinkerpop git commit: Merge branch 'tp31' into tp32
Posted by sp...@apache.org.
Merge branch 'tp31' into tp32
Conflicts:
pom.xml
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9ea319d5
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9ea319d5
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9ea319d5
Branch: refs/heads/TINKERPOP-1644
Commit: 9ea319d5d102432312f2044fc72e3668c1a8f7e2
Parents: 3fe223b cde8b31
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 13:01:03 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:01:03 2017 -0500
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9ea319d5/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index 09aeede,23f31f2..de8cf87
--- a/pom.xml
+++ b/pom.xml
@@@ -134,18 -127,9 +134,18 @@@ limitations under the License
</scm>
<properties>
<commons.configuration.version>1.10</commons.configuration.version>
+ <commons.lang.version>2.6</commons.lang.version>
+ <commons.lang3.version>3.3.1</commons.lang3.version>
- <groovy.version>2.4.8</groovy.version>
+ <groovy.version>2.4.9</groovy.version>
- <junit.version>4.12</junit.version>
+ <hadoop.version>2.7.2</hadoop.version>
+ <java.tuples.version>1.2</java.tuples.version>
+ <javadoc-plugin.version>2.10.1</javadoc-plugin.version>
+ <jcabi.version>1.1</jcabi.version>
<metrics.version>3.0.2</metrics.version>
+ <netty.version>4.0.42.Final</netty.version>
+ <slf4j.version>1.7.21</slf4j.version>
+ <snakeyaml.version>1.15</snakeyaml.version>
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<skipIntegrationTests>true</skipIntegrationTests>
[14/15] 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/dc87eb52
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/dc87eb52
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/dc87eb52
Branch: refs/heads/TINKERPOP-1644
Commit: dc87eb5268953b912ddba9b498693976ea84b391
Parents: d969900
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 9 13:15:04 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 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/dc87eb52/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/dc87eb52/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/dc87eb52/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) {
[06/15] 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/2a7314d8
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2a7314d8
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2a7314d8
Branch: refs/heads/TINKERPOP-1644
Commit: 2a7314d8a75fe9475cc4d55feb6fd8a62c2dd95d
Parents: 5cef755
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 13:37:42 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 2017 -0500
----------------------------------------------------------------------
.../groovy/jsr223/GremlinGroovyScriptEngine.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2a7314d8/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);
}
});
[03/15] 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/51761509
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/51761509
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/51761509
Branch: refs/heads/TINKERPOP-1644
Commit: 517615091270c5bc34390b4f3af3ff0fd8311a97
Parents: bafe07c
Author: BrynCooke <br...@gmail.com>
Authored: Wed Mar 8 12:24:46 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:09 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/51761509/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/51761509/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 {
[05/15] 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/fbe431ca
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fbe431ca
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fbe431ca
Branch: refs/heads/TINKERPOP-1644
Commit: fbe431ca387341b9cd212bd8364c9bf2701b2b1e
Parents: 9ea319d
Author: BrynCooke <br...@gmail.com>
Authored: Thu Mar 2 19:07:28 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:09 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/fbe431ca/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 04541d6..f14412e 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.
* 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.
* Deprecated `CustomizerProvider` infrastructure.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fbe431ca/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) {
[09/15] 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/242ba6ae
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/242ba6ae
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/242ba6ae
Branch: refs/heads/TINKERPOP-1644
Commit: 242ba6ae140930707d2e6dbfd669fa4133882f3c
Parents: 5176150
Author: BrynCooke <br...@gmail.com>
Authored: Wed Mar 8 13:23:30 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 2017 -0500
----------------------------------------------------------------------
.../jsr223/GremlinGroovyScriptEngine.java | 33 ++++++++++----------
1 file changed, 16 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/242ba6ae/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());
}
});
[10/15] 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/9a828655
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9a828655
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9a828655
Branch: refs/heads/TINKERPOP-1644
Commit: 9a828655aeac880890173eda513446fc9ac809be
Parents: 242ba6a
Author: BrynCooke <br...@gmail.com>
Authored: Wed Mar 8 13:26:31 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 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/9a828655/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;
[15/15] 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/07cac66a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/07cac66a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/07cac66a
Branch: refs/heads/TINKERPOP-1644
Commit: 07cac66a085802b49b52082ba70214a5f6ed3d37
Parents: 5dc7c99
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 16:17:40 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 2017 -0500
----------------------------------------------------------------------
.../groovy/jsr223/GremlinGroovyScriptEngine.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/07cac66a/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")
[04/15] 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/bafe07c3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/bafe07c3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/bafe07c3
Branch: refs/heads/TINKERPOP-1644
Commit: bafe07c39ab84b8787adb5205b89f67996175453
Parents: fbe431c
Author: BrynCooke <br...@gmail.com>
Authored: Tue Mar 7 16:54:58 2017 +0000
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:09 2017 -0500
----------------------------------------------------------------------
.../jsr223/GremlinGroovyScriptEngine.java | 69 ++++++++------------
1 file changed, 26 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bafe07c3/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) {
[11/15] 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/73e9e9f1
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/73e9e9f1
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/73e9e9f1
Branch: refs/heads/TINKERPOP-1644
Commit: 73e9e9f15cf96a48424e7c0364d7832fe3d94e23
Parents: 2a7314d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 16:13:06 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 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/73e9e9f1/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/73e9e9f1/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/73e9e9f1/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/73e9e9f1/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/73e9e9f1/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/73e9e9f1/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();
}
}
[12/15] 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/5cef7559
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5cef7559
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5cef7559
Branch: refs/heads/TINKERPOP-1644
Commit: 5cef75595cd2c92a8885a27395364e0bbe1424ae
Parents: 9a82865
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 8 13:31:52 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 9 13:16:10 2017 -0500
----------------------------------------------------------------------
gremlin-server/pom.xml | 5 -----
1 file changed, 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5cef7559/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>