Enjoy GraphDB! - graphdb jp #1(Japanese)
Post on 07-Jul-2015
3671 Views
Preview:
Transcript
Enjoy GraphDB!
Fungoing LLC / Satoshi Miyauchi
Twitter : @bibrost
~ Python with Bulbs and Rexster ~
Page : 1
宮内 聖 / Satoshi Miyauchi @bibrost
野良です
MongoDB、Python、Scalaとか
最近HotなのはやはりFluent
秋葉原に別荘を借りました
11月にカリフォルニア行ってきます
Page : 2
みなさんおつかれさまです
Page : 3
ここまでの話で
GraphDBの理解は
深まったはず
Page : 4
しかし
Page : 5
アプリで使えないと
意味がないよね
Page : 6
ということで
Page : 7
Enjoy GraphDB!
Page : 8
GraphDBへアクセスする方法
アプリから利用する方法はいくつかあります
1.ネイティブドライバで直接接続する
2.DB固有のHTTPインターフェイスを使う
3.TinkerPop/Gremlinを経由
4.Tinkerpop/Rexsterを経由(HTTP)
Page : 9
1.ネイティブドライバで直接接続する
・プロダクト毎、かなりAPIに差があるので、
心中の覚悟が必要
・メジャーどころは基本Javaなので、
ちょっと使うにはコストが高すぎる・・・
Page : 10
2.DB固有のHTTPインターフェイス
・やはりプロダクト毎、APIに差があるので
心中の覚悟が必要
・ものによってはサポートしていない動作も
多くどうもメインストリームではなさそう
Page : 11
3.TinkerPop/Gremlinを経由
・インターフェイスが共通化されているので
そこはとてもよい
・ただしJava(というかGroovy)なので
これはこれでヘビー。。。
Page : 12
4.Tinkerpop/Rexster経由(HTTP)
・HTTPでかつ共通化されたインターフェイス
使い勝手だけなら最良(管理画面付き)
・ただしコアとの距離がかなり遠いので
おそらくパフォーマンス悪い
+バージョンの追従がどうなのか・・・
Page : 13
どれも微妙。
Page : 14
とはいえどれか選ぶ必要はある
Page : 15
仮説
ディープに使い切るなら
→ 心中する覚悟で(1)をScala/Groovy/Clojureから使う
お金があるならNeo4j、無いならOrientDBがよさそう
GraphDBをそれなりに使いこなしたいなら
→ (3)をScala/Groovy/Clojureから使う
とりあえず体験してみたいなら
→ (4)を自分の慣れた言語から使う
Page : 16
というわけで(4)
Page : 17
GraphDBの現状
ネイティブドライバ以外はほとんど情報がない
→ まぁ、仕方ないね
ORMのような使い勝手を高めるライブラリはほとんどない
→ きっとまだそんな段階じゃないね
見渡す限り茨の道
→ 困ったら大元のドキュメントかソースを読むしかない
それで解決するかも不明(そもそも解決してないかも)
Page : 18
でも一応ORMぽいのもあった
Page : 19なんだか楽しそう!
Page : 20
Bulbs is an open-source Python persistence framework for graph
databases and the first piece of a larger Web-development toolkit
that will be released in the upcoming weeks.
Bulbs
Page : 21
It’s like an ORM for graphs, but instead of SQL,
you use the graph-traveral language Gremlin to query the
database.
グラフ用のORMみたいなもんさ。でも使うのはSQLじゃない。
Bulbsはgraph-traversal-language Gremlinを使うんだ
James Thornton
Page : 22
from bulbs.model import Node
from bulbs.datatype import Property, String
class Idea(Node):
element_type = "idea"
text = Property(String, nullable=False)
stub = Property(String,"make_stub")
def make_stub(self):
return utils.create_stub(self.text)
def after_created(self):
Relationship.create(self,"created_by",current_user)
なかなかコンパクトに書けそうなのでお試しにはよさそう
Page : 23
まずはこれを試そう
Page : 24
Enjoy!への道
1.JVM環境を入れておく(説明は割愛)
2.Rexsterのパッケージを落とす
3.Rexsterを起動する
4.Bulbsをインストールする
5.Enjoy!(幻想でした)
Page : 25
2.Rexsterのパッケージを落とす
https://github.com/tinkerpop/rexster/downloads
bulbsは0.5用なので0.5を落とそう
DL数は見なかったことにしよう
Page : 26
3.Rexsterを起動する
rexster-start.(sh|bat)
[INFO] WebServer - .:Welcome to Rexster:.
[INFO] GraphConfigurationContainer - Graph emptygraph - tinkergraph[vertices:0 edges:0] loaded
[INFO] RexsterApplicationGraph - Graph [tinkergraph] - configured with allowable namespace [tp:gremlin]
[INFO] GraphConfigurationContainer - Graph tinkergraph - tinkergraph[vertices:6 edges:6] loaded
[INFO] RexsterApplicationGraph - Graph [tinkergraph-readonly] - configured with allowable namespace [tp:gremlin]
[INFO] GraphConfigurationContainer - Graph tinkergraph-readonly - (readonly)tinkergraph[vertices:6 edges:6] loaded
[INFO] RexsterApplicationGraph - Graph [gratefulgraph] - configured with allowable namespace [tp:gremlin]
[INFO] GraphConfigurationContainer - Graph gratefulgraph - tinkergraph[vertices:809 edges:8049] loaded
[INFO] GraphConfigurationContainer - Graph emptysailgraph - not enabled and not loaded.
[INFO] GraphConfigurationContainer - Graph sailgraph - not enabled and not loaded.
[INFO] GraphConfigurationContainer - Graph orientdbsample - not enabled and not loaded.
[INFO] GraphConfigurationContainer - Graph neo4jsample - not enabled and not loaded.
[INFO] GraphConfigurationContainer - Graph dexsample - not enabled and not loaded.
[INFO] GraphConfigurationContainer - Graph remotetinkergraph - not enabled and not loaded.
[INFO] WebServer - Web Server configured with com..sun..jersey..config..property..packages: com.tinkerpop.rexster
[INFO] WebServer - Web Server configured with com..sun..jersey..spi..container..ContainerResponseFilters: com.tinkerpop.rexster.HeaderResponseFilter
[INFO] WebServer - Rexster Server running on: [http://localhost:8182]
[INFO] WebServer - No servlet initialization parameters passed for configuration: admin-server-configuration
[INFO] WebServer - Dog House Server running on: [http://localhost:8183]
[INFO] WebServer - RexPro serving on port: [8185]
[INFO] ShutdownManager$ShutdownSocketListener - Bound shutdown socket to /127.0.0.1:8184. Starting listener thread for shutdown requests.
Page : 27
3.Rexsterを起動する
http://localhost:8183/
管理画面もあるよ
Page : 28
4.Bulbsをインストールする
easy_install bulbs
Page : 29
Enjoy!
Page : 30
Code snippet
# Node class
class User(Node):
element_type = "user"
name = Property(String, nullable=False)
# add User
user = User(name=“bibrost")
user.save()
# add Relationsship
Relationship.create(User.get(from_id),"follow",User.get(to_id))
Page : 31
GraphDBの力がわかる問題
Page : 32
次のデータを取得するクエリを書いてください(言語等自由)
ユーザ[u]のまだ友達になっていない友達の友達
制限時間:20秒
Page : 33
g.v(u).out.aggregate(x).out.except(x)
Except pattern
Page : 34
g.v(u).out.aggregate(x).out.except(x)
u
Page : 35
g.v(u).out.aggregate(x).out.except(x)
u
Page : 36
g.v(u).out.aggregate(x).out.except(x)
u
x
Page : 37
g.v(u).out.aggregate(x).out.except(x)
u
x
Page : 38
g.v(u).out.aggregate(x).out.except(x)
u
x
Page : 39
f ff
友達[ f ]と友達の友達[ ff ]の差集合(difference set)を
求めるのがまさにExcept Pattern
※積集合を求めるRetain Patternもある
Page : 40
More Patterns
https://github.com/tinkerpop/gremlin/wiki
・ Backtrack Pattern
・ Except/Retain Pattern
・ Flow Rank Pattern
・ Paths Pattern
・ Loop Pattern
・ Split/Merge Pattern
・ Pattern Match Pattern
Githubのgremlinレポジトリに
色々あります
Page : 41
Demoコードの構成
https://github.com/bibrost/python-graphdb-demo
Tornade
Bulbs
Rexster
GraphDB
Page : 42
最後に
Page : 43
新しいパラダイムに触れることはとても
エキサイティングだし、勉強になる
まだGraphDB自体を使うところまでいっていないが
インスパイアされてMongoDB用のGraphを作るなど
実用的なメリットも既に受けている
(こちらは既にProductionに乗ってる)
Page : 44
そんなGraphDB、
今日からEnjoyしませんか
Page : 45
ドメインとWordPressをご用意しておきました
http://graphdb.jp/
Page : 46
いつでもアカウント発行します。
君もContributorにならなイカ?
Page : 47
ありがとうございました。
Enjoy GraphDB!~ Python with Bulbs and Rexster ~
top related