[
https://issues.apache.org/jira/browse/TINKERPOP-2438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17211324#comment-17211324
]
ASF GitHub Bot commented on TINKERPOP-2438:
-------------------------------------------
spmallette opened a new pull request #1346:
URL: https://github.com/apache/tinkerpop/pull/1346
https://issues.apache.org/jira/browse/TINKERPOP-2438
There are sometimes things you want to know about what a script is doing
before it goes to `eval()`. The immediate purpose is to extract timeouts passed
using `with()` so that they can be applied to a request as an override to the
server timeout. In this way, users who make the mistake of using this method
(meant for remote bytecode requests initially) with script submission
accidentally aren't left wondering why it didn't work as expected.
Performance doesn't appear to suffer too much from this added processing. I
wrote this little benchmark:
```text
gremlin> baseScript =
'g.with("evaluationTimeout",1).V().out("$a").in().where(outE().has("weight",$b).count().is($c)).order().by("name",desc).limit($d).project("x","y").by("name").by(outE().fold());'
==>g.with("evaluationTimeout",1).V().out("$a").in().where(outE().has("weight",$b).count().is($c)).order().by("name",desc).limit($d).project("x","y").by("name").by(outE().fold());
gremlin> [1,10,50,100,500,1000,5000,10000].collect {
......1> def binding = [a: RandomStringUtils.random(30), b:
rand.nextDouble(), c: rand.nextInt(), d: rand.nextInt()]
......2> def longScript =
(0..<it).collect{engine.createTemplate(baseScript).make(binding)}.join()
......3> def start = System.nanoTime()
......4> GremlinASTChecker.parse(longScript).getTimeout().get()
......5> [it, TimeUnit.MILLISECONDS.convert(System.nanoTime() - start,
TimeUnit.NANOSECONDS)]
......6> }
==>[1,1]
==>[10,2]
==>[50,8]
==>[100,13]
==>[500,59]
==>[1000,107]
==>[5000,514]
==>[10000,976]
```
I test on a fairly long sort of traversal - the `baseScript` - to see how
long it takes to do the timeout extraction with different length scripts
denoted by `longScript` which basically is just the `baseScript` concatenated
together by the number of lines we want to test. I random generated some data
in each script line to just be sure that no caching was at play (as we see in
the `GremlinGroovyScriptEngine`).
The output seems favorable in my mind. Parsing a single "good-sized" line of
Gremlin is basically instantaneous and even if someone went crazy and sent a
10000 line script (which will likely create bigger problems) it parses in under
1 second. Not feeling inclined to do much additional optimization based on
these numbers right now. If reviewing, please let me know if I'm making any bad
assumptions here in what that little microbenchmark is doing.
All tests pass with `docker/build.sh -t -n -i`
VOTE +1
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Provide a way for scripts to respect with() specification of timeout
> --------------------------------------------------------------------
>
> Key: TINKERPOP-2438
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2438
> Project: TinkerPop
> Issue Type: Improvement
> Components: server
> Affects Versions: 3.4.8
> Reporter: Stephen Mallette
> Assignee: Stephen Mallette
> Priority: Major
>
> This issue sorta relates to the Gremlin Console but I think it's generally a
> server side problem as it could easily occur with HTTP or just scripts sent
> over web sockets. Folks tend to see all the ways they can set timeouts and
> then mix/match them. It only remains a problem with sending a script as
> {{g.with("evalTimeout",100)}} because the server won't know that this value
> was set until the script is passed to {{eval()}} but by then it's too late
> because we would have already started the timeout countdown. While most
> users wouldn't send that as a bare script submission it's a common mistake in
> the Gremlin Console and similar environments where it is not clear you are
> working with a remote graph.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)