无法使用Gremlinpython

时间:2019-07-17 21:41:01

标签: python cassandra gremlin tinkerpop janusgraph

我尝试测试创建的图中的内容,以查看是否确实创建了节点。

创建用于测试的小型图形的代码:

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))

# in a loop add nodes and properties to get a small graph for testing
t = g.addV('testnode').property('val',1)
    for i in range(2,11):
    t = g.addV('testnode').property('val', i)
    t.iterate()

# proceed to create edge (as_ and from_ contain an underscore because as & from are python's reserved words)
g.V().has("val", 2).as_("a").V().has("val", 4).as_("b").addE("link").property("someproperty", "abc").from_("a").to("b").iterate()

list1 = []
list1 = g.V().has("val", 2).toList()
print(len(list1))
我希望终端中返回值“ 1”的

,这在先前测试时正确发生(现在失败了)。 但是,这将返回错误:

Traceback (most recent call last):
  File "test_addingVEs.py", line 47, in <module>
    list1 = g.V().has("val_i", 2).toList()
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/process/traversal.py", line 52, in toList
    return list(iter(self))
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/process/traversal.py", line 43, in __next__
    self.traversal_strategies.apply_strategies(self)
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/process/traversal.py", line 346, in apply_strategies
    traversal_strategy.apply(traversal)
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/driver/remote_connection.py", line 143, in apply
    remote_traversal = self.remote_connection.submit(traversal.bytecode)
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/driver/driver_remote_connection.py", line 54, in submit
    results = result_set.all().result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 405, in result
    return self.__get_result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/driver/resultset.py", line 81, in cb
    f.result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 398, in result
    return self.__get_result()
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/driver/connection.py", line 77, in _receive
    self._protocol.data_received(data, self._results)
  File "/home/user/.local/lib/python3.5/site-packages/gremlin_python/driver/protocol.py", line 98, in data_received
    "{0}: {1}".format(status_code, message["status"]["message"]))
gremlin_python.driver.protocol.GremlinServerError: 598: 
    A timeout occurred during traversal evaluation of [RequestMessage
    {, requestId=d56cce63-77f3-4c1f-9c14-3f5f33d4a67b, op='bytecode', processor='traversal', args={gremlin=[[], [V(), has(val, 2)]], aliases={g=g}}}]
     - consider increasing the limit given to scriptEvaluationTimeout

.toList()函数以前可以运行,但现在不再运行。 我的代码有什么问题,还是应该在其他地方寻找可能的原因?

1 个答案:

答案 0 :(得分:1)

好吧,该错误表明存在问题:

A timeout occurred during traversal evaluation of [RequestMessage
    {, requestId=d56cce63-77f3-4c1f-9c14-3f5f33d4a67b, op='bytecode', processor='traversal', args={gremlin=[[], [V(), has(val, 2)]], aliases={g=g}}}]
     - consider increasing the limit given to scriptEvaluationTimeout

当然,假设默认的scriptEvaluationTimeout为30秒,除非您有大量的顶点并且没有索引,否则返回您正在执行的查询的结果的时间应该不会花那么长时间。 “ val”。因此,鉴于您的图表非常小,我不明白为什么这样的执行会花这么长时间。

我不知道您所测试的环境是什么样的,但是如果您在功率不足的机器上运行所有JanusGraph / Cassandra,我想一些资源匮乏的事情可能需要很长时间才能完成执行。我认为我会尝试按照错误中的建议增加scriptEvaluationTimeout,以查看您必须增加多少才能使结果恢复。如果您在val上没有索引,则可能仍应添加索引(尽管我认为除非顶点数量大于代码所指示的数量,否则这不是您的问题)。