无法使用 Gremlinpython 使用“.toList()”列出 Janusgraph 中存在的所有顶点

Unable to list all vertices present in Janusgraph with ".toList()" using Gremlinpython

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

创建小图进行测试的代码:

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”,这在之前的测试中是正确的(现在失败了)。 然而,这returns一个错误:

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() 函数以前可以工作,但现在不行了。 我的代码有什么问题吗,还是我应该到别处寻找可能的原因?

嗯,报错说明问题所在:

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 秒,那么 return 您正在执行的查询的结果应该不需要那么长时间,除非您有大量的顶点并且您"val" 上没有索引。因此,鉴于您的图表非常小,我不明白为什么这样的执行会花费这么长时间。

我不知道你正在测试的环境是什么样的,但如果你 运行 所有 JanusGraph/Cassandra 都在一台动力不足的机器上,我猜有些东西资源匮乏可能需要很长时间才能执行。我想我会尝试按照错误中的建议增加 scriptEvaluationTimeout ,看看你必须增加多高才能得到结果。如果你在 val 上没有索引,你可能应该添加它们(尽管我不认为这是你的问题,除非顶点数大于你的代码指示)。