[ 
https://issues.apache.org/jira/browse/TINKERPOP-1644?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15922859#comment-15922859
 ] 

ASF GitHub Bot commented on TINKERPOP-1644:
-------------------------------------------

Github user robertdale commented on a diff in the pull request:

    https://github.com/apache/tinkerpop/pull/570#discussion_r105759976
  
    --- Diff: 
gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
 ---
    @@ -149,19 +159,64 @@
             }
         };
     
    +    private GremlinGroovyClassLoader loader;
    +
         /**
          * Script to generated Class map.
          */
    -    private ManagedConcurrentValueMap<String, Class> classMap = new 
ManagedConcurrentValueMap<>(ReferenceBundle.getSoftBundle());
    +    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();
    +
    +            return CompletableFuture.supplyAsync(() -> {
    +                try {
    +                    return loader.parseClass(script, generateScriptName());
    +                } catch (CompilationFailedException e) {
    +                    final long finish = System.currentTimeMillis();
    +                    log.error("Script compilation FAILED {} took {}ms {}", 
script, finish - start, e);
    +                    failedCompilationCount.incrementAndGet();
    --- End diff --
    
    That does the trick.  Making a separate comment about compilation timeout...



> Improve script compilation process and include metrics
> ------------------------------------------------------
>
>                 Key: TINKERPOP-1644
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1644
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: groovy
>    Affects Versions: 3.2.4
>            Reporter: Bryn Cooke
>            Assignee: stephen mallette
>
> Currently there is no synchronisation around script compilation. This means 
> that if a particularly heavy script is in use, many threads may end up 
> compiling the same script.
> It would seem like a good idea to have some some sort of synchronisation to 
> prevent ever getting to this stage.
> In addition, there will be cases where users will repeatedly submit broken 
> scripts to the server. In this case it is useful to log the error the first 
> time the script compilation is attempted and then cache the error for 
> subsequent runs.
> Finally I have found some scripts take in excess of 30 seconds to compile. To 
> aid performance debugging the script compilation times should be included in 
> the logs.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to