Hello, TinkerPop developers!
I’m the user of JanusGraph, as you may know, which is the graph database on
top of the gremlin server.
Recently on the investigation of why the gremlin-server uses UUID as its
request id,
I saw that the Builder class of
org.apache.tinkerpop.gremlin.driver.message.RequestMessage
class sets its requestId field as UUID.randomUUID() by default.
But I think it should be fixed not to be set by default. The reasons are
below;
- UUID.randomUUID() uses SecureRandom which grabs the lock at JVM level,
which means whole threads calling this API compete against each other.
- Getting random value from SecureRandom is somewhat CPU-intensive job.
- If a gremlin client sends requestId by itself, the costs above are
useless.
If you guys think my suggestion is reasonable, I will make this as git pull
request.
Index: gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/
driver/message/RequestMessage.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/
driver/message/RequestMessage.java (revision fa0a0ee64331bb1e67248137bd97fe
001554ac10)
+++ gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/
driver/message/RequestMessage.java (date 1512465656000)
@@ -112,7 +112,7 @@
*/
public static final class Builder {
public static final String OP_PROCESSOR_NAME = "";
- private UUID requestId = UUID.randomUUID();
+ private UUID requestId;
private String op;
private String processor = OP_PROCESSOR_NAME;
private Map<String, Object> args = new HashMap<>();
@@ -155,7 +155,7 @@
* Create the request message given the settings provided to the
{@link Builder}.
*/
public RequestMessage create() {
- return new RequestMessage(requestId, op, processor, args);
+ return new RequestMessage(requestId == null ?
UUID.randomUUID() : requestId, op, processor, args);
}
}