apache / incubator-hugegraph

A graph database that supports more than 100+ billion data, high performance and scalability (Include OLTP Engine & REST-API & Backends)
https://hugegraph.apache.org
Apache License 2.0
2.64k stars 517 forks source link

A way to count the total number of vertices/edges (In Cassandra) #322

Open imbajin opened 5 years ago

imbajin commented 5 years ago

Expected behavior

Easy and quick to estimate the total number of vertices or edges..

Actual behavior

It's obviously unreasonable to use gremlin's method (like g.V().count) to get the result. Like #102 , #37

Specifications of environment

Backend Version: Cassandra 3.0x or Cassandra 3.1x

imbajin commented 5 years ago

解决思路

就cassandra来说,有一个比较好的思路统计总的点边数 : 它自身提供了一个统计某个表总行数(Number of keys)的接口,可以快速得到一个预估但具体数值 (可通过JMX很方便的调用)

  1. 由于每个顶点由唯一的VertexID标识, 那么实际总顶点数一定 顶点表的行数
  2. 然后根据设置的的n副本策略,比如默认的3副本,则总的顶点数 各节点顶点表总行数之和 / 3 统计总的出/入边也可采用相同的思路, 具体的做法如下

使用方式

  1. 临时命令方式,适用于cassandra的3.0x版本,通过Cassandra自带的notetool执行 : /path/to/bin/nodetool cfstats |grep cfName -A 15 |grep "Number of keys" |awk '{print $5}' 可以直接得到本节点的某个表(cf)的数值, 然后通过工具批量分发其他节点汇总一下, 就能得到总行数.
  2. 另一种是通用的方式, 通过jmx的接口, 需要先启动JMX的agent服务, 默认Cassandra无此端口 ,然后通过比如: curl http://127.0.0.1:7777/jolokia/read/org.apache.cassandra.metrics:type=ColumnFamily,keyspace=hugegraph,scope=graph_vertices,name=EstimatedRowCount 的方式直接获得值, 可以很方便的整合到项目中

以上是这种思路的原理和实现方式, 虽然它的局限性比较明显, 但的确是一个简单快速统计出总点边的方法, 仅供大家参考~

javeme commented 5 years ago

@imbajin 非常感谢

javeme commented 3 years ago

补充Cassandra各版本的差异,可参考:

DSE 5.1 ~ 6.8: Number of partitions (estimate)

Apache Cassandra 3.0 ~ 2.2: Number of keys (estimate)