Gremlin Python in Web Application



我有一个python flask web应用程序,它使用gremlin_python查询Janus图形数据库。一个基本问题是初始化图遍历对象的正确方法。

  1. 是否可以初始化遍历g = traversal().withRemote(DriverRemoteConnection(...)并跨请求保留遍历变量g?(所有请求都针对同一图形。我试过这个,并开始间歇性地tornado.iostream.StreamClosedError
  2. 第二个选项是为每个请求创建遍历。我对 gremlin python 架构不够了解;每个请求执行此操作是否有大量开销?

谢谢

Gremlin Python 是 Gremlin 语言变体实现,请参见 http://tinkerpop.apache.org/docs/current/tutorials/gremlin-language-variants/。

因此,它确实依赖于GremlinServer来执行遍历。

作业:

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

将打开与服务器的 Websocket 连接。没有通过保留该连接的副本来"持久化"这样的事情。持久性机制都发生在服务器端。当我尝试以下代码时,我发现了这一点:

from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
import os
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
# test loading a graph
def test_loadGraph():
# make the local file accessible to the server
airRoutesPath=os.path.abspath("air-routes-small.xml")
# drop the existing content of the graph
g.V().drop().iterate()
# read the content from the air routes example
g.io(airRoutesPath).read().iterate()
vCount=g.V().count().next()
assert vCount==1000

上面的代码有效并加载空中航线示例。但它破坏了所有其他测试,因为现在下面提到的教程中所用服务器的默认现代图形已经消失了!

您可以打开与服务器的多个 websocket 连接,但它们都共享底层图形的相同"状态"。坏消息是,通过API影响这种状态并不容易,这是当前架构的深思熟虑的决定。目前有很多配置yaml和专有文件以及启动和停止服务器所涉及的。

我的改进建议 https://issues.apache.org/jira/projects/TINKERPOP/issues/TINKERPOP-2294?filter=allopenissues 是基于这种方法带来的挫败感。

特别是我分享你的"我对 gremlin python 架构不够了解"。恕我直言,这不是因为你或我在理解它方面有问题,而是因为它没有得到足够的解释。特别是缺少示例。这就是我开始的原因:http://wiki.bitplan.com/index.php/Gremlin_python - 一个旨在使开始使用 gremlin python 不那么痛苦的教程。

相关内容

最新更新