Web应用程序中的Gremlin Python [英] Gremlin Python in Web Application

查看:213
本文介绍了Web应用程序中的Gremlin Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a python flask web app, which is querying a Janus graph DB using gremlin_python. One basic question is the correct way to initialize the graph traversal object.

  1. 我可以初始化遍历g = traversal().withRemote(DriverRemoteConnection(...)并在请求中保留遍历变量g吗? (所有请求都针对同一张图.我尝试了此操作,并开始间歇性地获得tornado.iostream.StreamClosedError.
  2. 第二个选项是按请求创建遍历.我对gremlin的python架构不够了解.每个请求都需要这样做吗?
  1. Can I initialize my traversal g = traversal().withRemote(DriverRemoteConnection(...) and persist the traversal variable g across requests? (All requests are against the same graph. I tried this and started getting tornado.iostream.StreamClosedError intermittently.
  2. Second option is the create a traversal per request. I do not understand the gremlin python architecture well enough; is there a substantial overhead of doing this per request?

谢谢

推荐答案

Gremlin Python是Gremlin语言变体实现,请参见

Gremlin Python is a Gremlin Language Variant implementation see http://tinkerpop.apache.org/docs/current/tutorials/gremlin-language-variants/.

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

As such it does rely on a GremlinServer to execute traversals.

作业:

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

将打开与服务器的Websocket连接.通过保留该连接的副本没有持久"之类的事情.持久性机制都发生在服务器端.当我尝试以下代码时,我发现了这种困难的方法:

will open a websocket connection to the server. There is no such thing as "persisting" by keeping a copy of that connection. The persistence mechanisms all happen on the server side. I found this out the hard way when I tried out the following code:

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

以上代码可以正常工作并加载航路示例.但这破坏了所有其他测试,因为现在消失了下面提到的教程中所用服务器的默认现代图形!

The above code works and loads the air-routes example. But it breaks all other tests since now the default modern graph of the used server in the tutorial mentioned below is gone!

您可以打开与服务器的多个Websocket连接,但是它们都共享基础图的相同状态".坏消息是,通过API影响这种状态并不容易,这是当前体系结构的故意决定.当前,有很多配置yaml和属性文件以及启动和停止服务器的工作.

You can open multiple websocket connections to the server but they all share the same "state" of the underlying graph. The bad news is that it is not easy to influence this state via APIs which is a deliberate decision of the current architecture. Currently there is a lot of configuring yaml and propertries files and starting and stopping servers involved.

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

My Improvement proposal https://issues.apache.org/jira/projects/TINKERPOP/issues/TINKERPOP-2294?filter=allopenissues is based on the frustration this approach brings with it.

特别是,我分享了您的我对gremlin python体系结构了解得不够好".恕我直言,这不是因为您或我在理解它时遇到问题,而是因为它解释得不够.尤其是缺少示例.这就是我开始的原因: http://wiki.bitplan.com/index.php/Gremlin_python -本教程旨在使减轻gremlin python入门的痛苦.

Especially I share your "I do not understand the gremlin python architecture well enough". IMHO this is not because you or i have a problem in understanding it but because it is not explained well enough. Especially examples are missing. This is why I started: http://wiki.bitplan.com/index.php/Gremlin_python - a tutorial that is intended to make getting started with gremlin python less painful.

这篇关于Web应用程序中的Gremlin Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆