gpt4 book ai didi

python - Web 应用程序中的 Gremlin Python

转载 作者:行者123 更新时间:2023-12-01 15:01:08 24 4
gpt4 key购买 nike

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

  • 我可以初始化我的遍历g = traversal().withRemote(DriverRemoteConnection(...)并持久化遍历变量 g跨请求? (所有请求都针对同一张图。我尝试了这个并开始间歇性地收到 tornado.iostream.StreamClosedError
  • 第二个选项是为每个请求创建一个遍历。我不太了解 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 入门不那么痛苦的教程。

    关于python - Web 应用程序中的 Gremlin Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55876563/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com