【发布时间】:2021-05-28 00:51:42
【问题描述】:
我在 python 中使用 Gremlin,我创建了一个函数来添加一个新的顶点以避免创建重复:
def add_vertex(label, properties):
first_attribute = list(properties.keys())[0]
check_vertex = g.V().has(first_attribute, properties[first_attribute]).toList()
if check_vertex:
return check_vertex[0]
v = g.addV(label)
for attribute in properties:
v.property(attribute, properties[attribute])
return v.next()
'label' 是顶点的名称,'properties' 是一个带有属性的字典。
为了提高添加新顶点的性能,我还根据属性的第一个属性添加了一个索引。
使用包含 284.000 个元素的字典,时间为:
- 12 分钟不检查顶点(仅限顶点插入)
- 25 分钟完成整个功能
Gremlin 有可能这么慢吗?难道不能提高性能吗? 我觉得这个时机太过分了,不是吗?
还有另一种添加顶点而不重复的方法吗?
谢谢。
【问题讨论】:
-
澄清一下,您想添加 284K 顶点,并且您想在添加之前检查每个顶点是否已经存在?
-
@KelvinLawrence 完全正确,因为我不想重复。但是检查再添加一个新的顶点,作为一个新的边,很慢。
标签: python performance indexing gremlin vertex