无法使用gremlinpython列出janusgraph中的所有顶点

k2arahey  于 2021-06-14  发布在  Cassandra
关注(0)|答案(1)|浏览(757)

我试着测试我创建的图中的内容,看看是否确实创建了节点。
创建用于测试的小型图形的代码:

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()函数以前确实有效,但现在不行了。我的代码中是否有任何错误,或者我是否应该寻找其他可能的原因?

cl25kdpy

cl25kdpy1#

这个错误说明了问题:

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 无论如何,您可能应该添加这些(尽管我不认为这是您的问题,除非顶点计数大于代码所指示的值)。

相关问题