Weitere ähnliche Inhalte
Ähnlich wie Spark graph framesとopencypherによる分散グラフ処理の最新動向 (20)
Spark graph framesとopencypherによる分散グラフ処理の最新動向
- 2. / 45
自己紹介
• 加嵜 長門
• 2014年4月~ DMM.comラボ
• Hadoop基盤構築
• Spark MLlib, GraphXを用いたレコメンド開発
• 好きな言語
• SQL
• Cypher
2
- 4. / 45
GraphFramesとは?
• Spark Summit East 2016
• 2016/2/18
4
https://spark-summit.org/east-2016/events/graphframes-graph-queries-in-spark-sql/
- 10. / 45
openCypher
• オープンソースのグラフクエリ言語
• Neo4jのCypherから派生
• SQLに似た宣言的な記述が可能
10
MATCH (cypher:QueryLanguage)-[:QUERIES]->(graphs)
MATCH (cypher)<-[:USES]-(u:User) WHERE u.name IN [‘Oracle’, ‘Apache Spark’, ‘Tableau’, ‘Structr’]
MATCH (openCypher)-[:MAKES_AVAILABLE]->(cypher)
RETURN cypher.attributes
-----------
[‘awesome’,…]
http://www.opencypher.org/
- 12. / 45
GraphFramesを試す
• Spark Shell でインタラクティブに試す
• Spark 1.4以上に対応
• DataFramesの利点を活かすなら最新版を推奨
12
# spark をダウンロード
$ wget http://ftp.jaist.ac.jp/pub/apache/spark/spark-1.6.0/spark-1.6.0-bin-hadoop2.6.tgz
$ tar xzvf spark-1.6.0-bin-hadoop2.6.tgz
# graphframesパッケージを指定してspark-shellを起動
$ spark-1.6.0-bin-hadoop2.6/bin/spark-shell --packages graphframes:graphframes:0.1.0-spark1.6
- 13. / 45
GraphFramesを試す
• Build.sbt を利用
13
resolvers += "Spark Packages Repo" at "http://dl.bintray.com/spark-packages/maven"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "1.6.0",
"org.apache.spark" %% "spark-sql" % "1.6.0",
"org.apache.spark" %% "spark-graphx" % "1.6.0",
"graphframes" % "graphframes" % "0.1.0-spark1.6“
)
- 14. / 45
GraphFrames – アイテムレコメンドの実行例
14
// graphframesパッケージのインポート
scala> import org.graphframes._
import org.graphframes._
// Vertex(頂点)となるDataFrameを作成
scala> val v = sqlContext.createDataFrame(List(
| (0L, "user", "u1"),
| (1L, "user", "u2"),
| (2L, "item", "i1"),
| (3L, "item", "i2"),
| (4L, "item", "i3"),
| (5L, "item", "i4")
| )).toDF("id", "type", "name")
v: org.apache.spark.sql.DataFrame = [id: bigint, type: string, name: string]
u1
u2
i1
i2
i3
i4
ユーザ
アイテム
- 15. / 45
GraphFrames – アイテムレコメンドの実行例
15
// Edge(辺)となるDataFrameを作成
scala> val e = sqlContext.createDataFrame(List(
| (0L, 2L, "purchase"),
| (0L, 3L, "purchase"),
| (0L, 4L, "purchase"),
| (1L, 3L, "purchase"),
| (1L, 4L, "purchase"),
| (1L, 5L, "purchase")
| )).toDF("src", "dst", "type")
e: org.apache.spark.sql.DataFrame = [src: bigint, dst: bigint, type: string]
// GraphFrameを作成
scala> val g = GraphFrame(v, e)
g: org.graphframes.GraphFrame = GraphFrame(v:[id: bigint, attr: string, gender: string],
e:[src: bigint, dst: bigint, relationship: string])
u1
u2
i1
i2
i3
i4
購入ログ
- 16. / 45
GraphFrames – アイテムレコメンドの実行例
16
// レコメンドアイテムの問い合わせ例
scala> g.find(
| " (user1)-[]->(item1); (user2)-[]->(item1);" +
| " (user2)-[]->(item2); !(user1)-[]->(item2)"
| ).groupBy(
| "user1.name", "item2.name"
| ).count().show()
name name count
u1 i4 2
u2 i1 2
u1
u2
i1
i2
i3
i4
共通の商品を
購入したユーザ
まだ購入していないアイテムをレコメンド
- 18. / 45
BSP, Pregel, Graph
18
Pregel
BSP
Apache Hama
グラフ特化
開発
実装
実装
活用
継承
影響
Open Graph
Graph Search
Knowledge Graph
- 28. / 45
GraphX Pregel API
28
引用:http://www.slideshare.net/SparkSummit/graphframes-graph-queries-in-spark-sql-by-ankur-dave
- 32. / 45
Partition Strategy
• 次数 10000
• Partition数 100
32
Vn
V1
V2
V10000
・
・
・
Partition 1
Partition 2
Partition 100
・
・
・
?
- 33. / 45
Partition Strategy
• RandomVertexCut
• Hash(src, dst)
33
Vn
V1
V2
V10000
・
・
・
Partition 1
Partition 2
Partition 100
・
・
・
Vn V1
Vn V2
Vn V10000
1 Partition あたり
平均 100 Edges
I/O効率が悪い
- 34. / 45
Partition Strategy
• EdgePartition1D
• Hash(src)
34
Vn
V1
V2
V10000
・
・
・
Partition 1
Partition 2
Partition 100
・
・
・
Vn V1
Vn V2
Vn V10000
srcに対して
Partitionが決まる
I/Oが発生する
Partitionを限定
できる
- 35. / 45
Partition Strategy
• EdgePartition1D
• Hash(src)
35
Vn
V1
V2
V10000
・
・
・
Partition 1
Partition 2
Partition 100
・
・
・
srcに対して
Partitionが決まる
Edge の順方向
にしか意味が無い
Vn V1
Vn V2
Vn V10000
- 36. / 45
Partition Strategy
• EdgePartition2D
36
Vn
V1
V2
V10000
・
・
・
* * *Vn
V1 V2 V10000
Partition 1
・・・
10/100
Partitions
Partition 100
- 38. / 45
Partition Strategy
• EdgePartition2D
38
*
*
*
Vn
V1
V2
V10000
Vn
V1
V10000
V2
・
・
・
・
・
・
Vi
Vj
・
・
・
Vk
Vn
V1 V2 V10000・・・
高々
20/100 Partitions
=20%
200/10000 なら
2%
- 39. / 45
GraphFrames vs. Neo4j
39
引用:http://www.slideshare.net/SparkSummit/graphframes-graph-queries-in-spark-sql-by-ankur-dave
- 40. / 45
GraphFrames × Spark 2.0
40
引用: http://www.slideshare.net/databricks/2016-spark-summit-east-keynote-matei-zaharia
- 43. / 45
参考文献
• Neo4j Webinar
• http://neo4j.com/webinars/
• Bootstrapping Recommendations with Neo4j
• Fraud Detection with Neo4j
• Natural Language Processing with Graphs
• etc.
43
- 44. / 45
参考文献
• Apache Spark Graph Processing
• Rindra Ramamonjison
• http://www.amazon.co.jp/dp/1784391808
44
- 45. / 45
参考文献
• Graph Mining: Laws, Tools, and Case Studies
• Deepayan Chakrabarti, Christos Faloutsos
• http://www.amazon.com/dp/B00AF2CVE6
45