algorithm - 分布式图搜索
问题描述
给定一个跨多个节点分区的巨大图。每个节点都包含一组顶点和全局邻接信息的一些分区。
给定源顶点及其所在节点的地址,在此分布式图上实现 BFS 的最佳方法是什么。该解决方案应该可靠且快速。
解决方案
有很多方法可以完成这项工作。这是一种利用https://en.wikipedia.org/wiki/MapReduce的简单方法。
我将假设您可以使用三个机器池。
- 您的图形数据库
- 分布式键/值存储(例如 Cassandra)
- 映射/减少工作者(例如 Hadoop)
然后算法进行如下:
Insert into your kv store the fact that you reached the starting vertex at `(0, Null)` where the pair is `(generation, from)`:
while not finished and last generation found new stuff:
Do a mapreduce from your k/v store:
map gets (vertex, (found_generation, from_vertex):
- sends:
if found_generation is current_generation:
foreach new_vertex adjacent to vertex (lookup in graph db):
send: new_vertex: (current_generation + 1, vertex)
else:
send: vertex: (found_generation, from_vertex)
reduce gets (vertex, (found1, v1), (found2, v2), ...)
search list for sample record with minimum found
store minimum found back in k/v store
if found target:
recursively walk k/v store to reconstruct the path
clear k/v store of working set
return answer
关键是所有对图和 k/v 存储的查找都是分布式的,并且 map/reduce 内的所有工作也是分布式的。每一代的同步是最小的。因此,这将以分布式方式完成大部分工作。
和性能说明。一般来说,从单台机器上的简单实现到分布式机器的成本和资源增加了一个数量级,随之而来的是巨大的可扩展性。从简单的实现到经过良好优化的实现往往会在性能上提高 1-2 个数量级,但您仅限于一台机器可以做的事情。仔细选择采取哪种方法。仅在您确实需要时才分发。
推荐阅读
- php - 将 CodeIgniter 1.7.2 升级到 3.1.6 最有效的方法
- python-3.x - 在集群上部署 PySpark 作业
- stenciljs - StencilJS 插槽内容闪烁可见内容
- microsoft-teams - MS Teams:当任务模块通过深度链接打开时,如何为它定义 closeHandler?
- pandas - 解析特殊字符的xml时面临的错误
- java - 将一个字节数组 (BLOB IBM DB2) 中的多个图像导出到磁盘
- r - 如何在特定列之后添加空列并根据 R 闪亮中的用户特定替换值
- python - 如何基于过滤计算数据框列中的值
- google-cloud-platform - Google Cloud Functions 中的 HTTPS 是否支持使用 PKI 的 mTLS?
- javascript - 如何重置颜色网格?