python - Web 应用程序中的 Gremlin Python
问题描述
我有一个 python 烧瓶网络应用程序,它使用gremlin_python
. 一个基本问题是初始化图遍历对象的正确方法。
- 我可以初始化我的遍历并跨请求
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 入门不那么痛苦的教程。
推荐阅读
- redmine - Redmine 中的 Backlogs 插件出现错误
- ios - iOS侧载expo应用水平翻转
- sql - SQL查询查找表中最后创建的记录
- javascript - 如何使用 React.js 将 state 属性传递给构造函数中的子组件?
- tensorflow - 我没有让 keras fit_generator 与混合(图像和数字)输入一起工作
- html - 如何逐个移动元素
- python - 上下文不打印 Django
- r - error en METRIC.EB .local(x, …) 中的错误:RasterLayer 没有 NA 像元(要计算距离)
- svg - Highcharts Scrollbar向上箭头在点击时抛出错误
- python - 如何在给定文件的给定行号处附加时间?