Can Graph DBs perform well with unspecified end nodes?

核能气质少年 提交于 2021-02-11 16:11:38

问题


I have been experimenting with neo4j for a very specific scenario and I have been unable to get it to perform well - queries take minutes to return. I am wondering if this is a case of the wrong technology for the job?

A simplified version of my scenario is below. I have Towns that are linked to each other via routes. Each route has a distance.

The question I'm trying to ask is: calculate the shortest route from Town A to every other town reachable from Town A. In this scenario, there are an unspecified number of end nodes. This query takes minutes to return with a small dataset and doesn't return at all for larger data sets with 50,000 nodes.

If I ask the question: calculate the shortest route from Town A to Town E the response is seemingly instant. In this scenario, both the start and end nodes are known.

My question is, are graph dbs good for the open ended questions (calculate the shortest route from Town A to every other town reachable from Town A)? If so, is it just my approach to structuring the data that is hampering the performance?


回答1:


Your data structure looks good (maybe you could add an "Intersection" vertex with a "ROAD" edge with a length stored on the ROAD edge, but not sure what data you have available) and YES this is most definitely a good use case for graphs.

I haven't used Neoj4 much, but the problem most likely is the approach you are taking with the algorithm (query) involved.

Neo4j should easily handle what you're looking to accomplish. I would recommend watching some Neo4j videos on the topic and mimic their approach to the shortest path algorithms.

Neo4j(Shortest-Path): https://youtu.be/baEeRfuK1Nk

The graph database I've always used to implement these has always been on TigerGraph, but all graph databases would be able to handle 50,000 nodes quickly.

TigerGraph (Shortest-Path): https://youtu.be/Ra0qORVKsWs

EDITED (adding documentation links):

NEO4J

Single Source Shortest Path algorithm

Docs: https://neo4j.com/docs/graph-algorithms/current/labs-algorithms/single-source-shortest-path/

TIGERGRAPH

Single-Source Shortest Path (unweighted)

Docs: https://docs.tigergraph.com/v/2.6/graph-algorithm-library#single-source-shortest-path-unweighted

Code: https://github.com/tigergraph/gsql-graph-algorithms/blob/master/algorithms/schema-free/shortest_ss_no_wt.gsql

Single-Source Shortest Path (weighted)

Docs: https://docs.tigergraph.com/v/2.6/graph-algorithm-library#single-source-shortest-path-weighted

Code: https://github.com/tigergraph/gsql-graph-algorithms/blob/master/algorithms/schema-free/shortest_ss_any_wt.gsql



来源:https://stackoverflow.com/questions/65007546/can-graph-dbs-perform-well-with-unspecified-end-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!