前言
下載鏈接
鏈接:https://pan.baidu.com/s/1P7eIelXHI0l5pSEBFCCF7Q
提取碼:vax4
一、HugeGraph簡介
最近在搞好友推薦方便的工作,選擇了圖數據的方法,使用並學習了HugeGraph,再次記錄一下。
HugeGraph是百度在2018年中旬開源的一款圖數據庫(Graph Database)系統,可以存儲海量的頂點(Vertex)和邊(Edge)。實現了Apache ThinkerPop 3[1]框架,支持Gremlin圖查詢語言[2]。HugeGraph支持多用戶並行操作,用戶可輸入Gremlin查詢語句,並及時得到圖查詢結果。也可以再用戶程序中調用hugeGraph API進行圖分析或查詢。
二、HugeGraph特性
HugeGraph支持在線及離線環境下的圖操作,支持批量導入數據,支持高效的負責關聯關系分析,並且能夠與大數據平台無縫集成。
HugeGraph具備如下特點:
- 基於ThinkerPop 3框架實現,支持Gremlin查詢語言;
- 支持從TXT、CSV、JSON等格式的文件中批量導入數據;
- 具備獨立的Schema元數據信息,方便第三方系統集成;
- 具備可視化操作界面,降低用戶使用門檻;
- 存儲系統采用插件方式,支持RocksDB、Cassandra、ScyllaDB、HBase及Mysql等多種后端;
- 優化的圖接口,最短路徑、K步連通子圖、K步到達鄰接點等;
- 支持屬性圖,頂點和邊均可添加屬性,支持豐富的屬性類型;
- 可以對邊和頂點的屬性建立索引,支持精確查詢、范圍查詢、全文檢索;
- 支持4種頂點ID策略,之間ID、自動生成ID、用戶自定義字符串ID和用戶自定義數據ID;
- 支持與Hadoop、Spark GraphX等大數據系統集成,支持Bulk Load操作。
三、HugeGraph框架模塊
- HugeGraph-Server: HugeGraph-Server是HugeGraph項目的核心部分,包含Core、Backend、API等子模塊;
- Core:圖引擎實現,向下連接Backend模塊,向上支持API模塊;
- Backend:實現將圖數據存儲到后端,支持的后端包括:Memory、Cassandra、ScyllaDB、RocksDB、HBase以及Mysql,用戶根據實際情況選擇一種即可;
- API:內置REST Server,向用戶提供RESTful API,同時兼容Gremlin查詢。
- HugeGraph-Client:HugeGraph-Client提供了RESTful API的客戶端,用於連接HugeGraph-Server,目前僅實現Java版,其他語言用戶可自行實現;
- HugeGraph-Studio:HugeGraph-Studio是HugeGraph的Web可視化工具,可用於執行Gremlin語句及展示圖;
- HugeGraph-Loader :HugeGraph-Loader是基於HugeGraph-Client的數據導入工具,將普通文本數據轉化為圖形的頂點和邊並插入圖形數據庫中;
- HugeGraph-Spark:基於Spark GraphX的圖分析工具 ,HugeGraph-Spark能在圖上做並行計算,例如PageRank算法等;
- HugeGraph-Tools:HugeGraph-Tools是HugeGraph的部署和管理工具,包括管理圖、備份/恢復、Gremlin執行等功能。
總結:部署HugeGraph需要HugeGraph-Server,在網頁上操作圖需要HugeGraph-Studio,在java項目中操作圖需要HugeGraph-Client,其他三個視情況需要的時候再部署使用。
四、HugeGraph安裝部署(注意HugeGraph-Server和HugeGraph-Studio版本要匹配)
官方文檔:https://hugegraph.github.io/hugegraph-doc/download.html
4.1 安裝HugeGraph-Server(必須)
依賴:
JDK1.8
使用使用的是RocksDB存儲則需要GCC >= 4.3.0 ,下面的步驟假設使用RocksDB作為存儲
步驟1:(此時版本為:https://github.com/hugegraph/hugegraph/releases/download/v0.10.4/hugegraph-0.10.4.tar.gz)
# 下載tar包
wget https://github.com/hugegraph/hugegraph/releases/download/v${version}/hugegraph-${version}.tar.gz
tar -zxvf hugegraph-${version}.tar.gz
步驟2:
修改 hugegraph.properties
backend=rocksdb
serializer=binary
rocksdb.data_path=.
rocksdb.wal_path=.
步驟3:
初始化數據庫(僅第一次啟動時需要)
cd hugegraph-${version}
bin/init-store.sh
步驟4:
啟動server(如果端口8080被占用可以修改conf/rest-server.properties中端口8080為其他端口如9080)
bin/start-hugegraph.sh
Starting HugeGraphServer...
Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK
步驟5:
查看服務狀態:
# curl請求restuflAPI,結果返回200,代表server啟動正常
echo `curl -o /dev/null -s -w %{http_code} "http://localhost:8080/graphs/hugegraph/graph/vertices"`
步驟6:
# 停止server
$cd hugegraph-${version}
$bin/stop-hugegraph.sh

4.2 安裝HugeGraph-Studio
步驟1:
# 下載tar包並解壓(此時版本為:https://github.com/hugegraph/hugegraph-studio/releases/download/v0.10.0/hugegraph-studio-0.10.0.tar.gz)
wget https://github.com/hugegraph/hugegraph-studio/releases/download/v${version}/hugegraph-studio-${version}.tar.gz
tar zxvf hugegraph-studio-${version}.tar.gz
步驟2:
修改配置文件hugegraph-studio.properties
- 將配置項
studio.server.host
的值localhost
修改成機器名或 IP,這是 HugeGraphStudio 對外提供服務的host
,如果只需要本地訪問則保持不變即可; - 將配置項
studio.server.port
的值8088
修改成想要的端口,這是 HugeGraphStudio 對外提供服務的port
; - 將配置項
graph.server.host
的值localhost
修改成 HugeGraphServer 的host
,HugeGraphStudio 通過此項和graph.server.port
與 HugeGraphServer 建立連接; - 將配置項
graph.server.port
的值8080
修改成 HugeGraphServer 的port
,HugeGraphStudio 通過graph.server.host
和此項與 HugeGraphServer 建立連接; - 將配置項
graph.name
的值hugegraph
修改成要連接的 HugeGraphServer 的圖名,目前只允許連接一個圖。
# 啟動HugeGraph-Studio
$ cd hugegraph-studio-${version}
$ bin/hugegraph-studio.sh
步驟3:
瀏覽器打開:http://localhost:8088即可訪問。
五、HugeGraph,Neo4j,Titan三種圖數據庫性能對比
官網給了一個性能測試的報告:https://hugegraph.github.io/hugegraph-doc/performance/hugegraph-benchmark-0.5.6.html
總結起來就是:
- 批量插入性能:HugeGraph(RocksDB) > Neo4j > Titan(thrift+Cassandra)
- 遍歷性能:Neo4j > HugeGraph(RocksDB) > Titan(thrift+Cassandra)
- 圖常用分析方法性能:FS場景,HugeGraph性能優於Neo4j和Titan,K-neighbor和K-out場景,HugeGraph能夠實現在5度范圍內秒級返回結果
- 社區聚類算法性能 Neo4j > HugeGraph > Titan
當時選擇HugeGraph的原因一是需求需要導大量的數據,涉及大約十幾億的插入,所以需要找一個插入性能高的,並且好友關系變動的時候也需要異步更新圖關系。而是HugeGraph雖然是新秀,但是中文官方文檔很簡介清楚,利於學習使用。
參考:
作者:王小冬
鏈接:https://www.jianshu.com/p/c124f748877d
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。