I have a super easy gremlin query which I send to a IBM Cloud hosted JanusGraph with gremlin console. Strangely, the execution time is very fast sometimes and then again very slowly. What can that be? The property uid
is of type string and could be an GUID but also something other.
gremlin> g.V().has('uid', 'f287342c-ff84-4102-8f18-f3aa759470a7').hasLabel('product').profile()
==>Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
JanusGraphStep([],[uid.eq(f287342c-ff84-4102-8f... 1 1 1107.212 100.00
\_condition=(uid = f287342c-ff84-4102-8f18-f3aa759470a7 AND ~label = product)
\_isFitted=false
\_query=[]
\_orders=[]
\_isOrdered=true
optimization 0.014
optimization 0.055
scan 0.000
\_condition=VERTEX
\_query=[]
\_fullscan=true
>TOTAL - - 1107.212 -
gremlin> g.V().has('uid', 'f287342c-ff84-4102-8f18-f3aa759470a7').hasLabel('product').profile()
==>Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
JanusGraphStep([],[uid.eq(f287342c-ff84-4102-8f... 1 1 129.861 100.00
\_condition=(uid = f287342c-ff84-4102-8f18-f3aa759470a7 AND ~label = product)
\_isFitted=false
\_query=[]
\_orders=[]
\_isOrdered=true
optimization 0.014
optimization 0.056
scan 0.000
\_condition=VERTEX
\_query=[]
\_fullscan=true
>TOTAL - - 129.861 -
gremlin> g.V().has('uid', 'f287342c-ff84-4102-8f18-f3aa759470a7').hasLabel('product').profile()
==>Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
JanusGraphStep([],[uid.eq(f287342c-ff84-4102-8f... 1 1 2581.514 100.00
\_condition=(uid = f287342c-ff84-4102-8f18-f3aa759470a7 AND ~label = product)
\_isFitted=false
\_query=[]
\_orders=[]
\_isOrdered=true
optimization 0.024
optimization 0.094
scan 0.000
\_condition=VERTEX
\_query=[]
\_fullscan=true
>TOTAL - - 2581.514
I found the solution by adding an index to property uid
. I thought, JanusGraph will do this automatically, but that's not how it is. Use follwing steps on the JanusGraph gramlin console.
gremlin> graph = ConfiguredGraphFactory.open('g')
gremlin> mgmt = graph.openManagement()
gremlin> uidKey = mgmt.getPropertyKey('uid')
gremlin> mgmt.buildIndex('uidIndex', Vertex.class).addKey(uidKey ).buildCompositeIndex()
gremlin> mgmt.commit()
This is an adaption of the JanusGraph documentation.