Upload
kishimotosc
View
3.001
Download
3
Embed Size (px)
DESCRIPTION
"PyCon JP 2011"のライトニングトークでの資料です。 Cassandraベースでどのようにトランザクションを実現したか(の概略)と、 webフレームワークであるweb2py用のCMSプラグインのご紹介です。
Citation preview
Cassandraのトランザクションサポート化&
web2pyによるCMS用プラグイン開発
Transaction support on Cassandra&
CMS plugins for web2py
株式会社エスキュービズム
● おまえ、誰よ?
岸本 康二 @
Pythonで受託と研究開発などを行っています
Python歴は10年ちょっと
Who are you?
Koji KISHIMOTO
社内にPython好きが多すぎた成果物
中級以上向け
> we_love_python = True> if we_love_python:> print PythonBook()
①Cassandraのトランザクションサポート化
①Transaction support on Cassandra
● Cassandra って?
分散KVS(Key-Value Store)
ApacheのTop Level Projectの1つFacebook社がOSS化した物が基に
What is Cassandra?
distributed key-value store
● とってもスケーラブル!
ノード数 →
↑パフォーマンス
分散KVS RDB
ノードを追加するだけで処理性能がリニアにUP↑
Scalable!
# of nodes
performance
Simply, add nodes and you'll get more power!
● Cassandra + トランザクション
分散KVSでトランザクションが出来たら最高!
↓もう高価な有償RDBは不要にな(ry
Cassandra + Transaction
A Farewell To RDBs
It is desirable for distributed KVS to have the transation function!
● Cassandra + トランザクション
でも、往々にして「分散KVSでトランザクション?(笑)」
・・・となるのがオチ
↑CAP定理と通説が原因
Cassandra + Transaction
CAP theorem and common belief
transaction on distributed KVS? ha ha ha!
● CAP定理
C: 一貫性A: 可用性P: 分断耐性
CAP theorem
(Consistency)(Availability)(Partition tolerance)
● CAP定理での誤解 Misunderstanding about CAP theorem
× 3つの保証を提供できない
○ 3つの保証を「同時に」提供できない
It is impossible to provide all three
It is impossible to simultaneouslysimultaneouslysimultaneouslysimultaneously provide all three
「同時」ではなかったら?What will happen if the system does notnotnotnot simultaneously provide all three?
● Cassandraの場合
C A P 定理
In the case of Cassandra
two of "C", "A" and "P"
Solution: write & read pair
書き込み時のみではなく、読み込み時にも処理を行う( = "Read Repair")
→ 強一貫性も実現realization of "Consistency"
"結果整合性"と関係"eventual consistency"
● トランザクション Transaction on Cassandra
書き込み時のみではなく、読み込み時にも処理を行う( = "Read Repair")
というアイディアをトランザクションに応用したら?!
The same idea is availabe for the transaction!Isn't it?
● 「NanaHoshi」を開発 We've developed "NanaHoshi"
実際に実装してみて振り返ると"BASE"型トランザクションのコンセプトと似てましたNanaHoshi has "BASE" type transaction mechanism
BA: Basically AvailableS : Soft-state ← Important!E : Eventual consistency
● 結論 Conclusion
分散KVSでトランザクションできますWe can use the transaction on distributed KVS.
業務システム構築に利用できますしかも
スケーラブルに
More info More info More info More info →→→→http://echttp://echttp://echttp://ec----cube.eccube.eccube.eccube.ec----orange.jp/lp/nanahoshiorange.jp/lp/nanahoshiorange.jp/lp/nanahoshiorange.jp/lp/nanahoshi////
● NanaHoshiの構造
Cassandra
Thrift IF
Abstract access layer
Object mapper
Transaction logic
Structure of "NanaHoshi"
● NanaHoshiの構造
Cassandra
Thrift IF
Abstract access layer
Object mapper
Transaction logic
Structure of "NanaHoshi"
ここが全部Python。Cassandra,Thrift関係以外は
全て標準機能・モジュールで構成
● 簡単サンプルコード Simple sample code
### Initialization
connection = CassandraConnection()connection.open()connection.set_keyspace('TEST')### Preparation
lockable = ModelLockable(connection, 'key')lockable.load()
・・・(etc.)### Transaction
transaction = ModelTransaction(connection)try:
transaction.start()if not lockable.join(transaction):
raise Exception()lockable.load()lockable.data += 10lockable.save()if not transaction.end():
raise Exception()except:
transaction.forget()
Web server:Tornado
● NanaHoshiの構造
Cassandra → another DB
Thrift IF ( → another access IF)
Abstract access layer
Object mapper
Transaction logic
Structure of "NanaHoshi"
実は、Cassandra以外
でも動かせる設計です。
10月初旬にCassandraイベントを行う予定です。
DataStaxさんからも参加予定です。
②web2pyによるCMS用プラグイン開発
②CMS plugins for web2py
● web2py って?
Webアプリケーションフレームワーク
OSSで学習が非常に容易。最近はDjangoに追い付け追い越せの勢いです。
What is web2py?
Web application framework
● CMSへの利用 Application to CMS
株のSNSサイト『みんなの株式』
(みんかぶ)内でも動作中。
実案件でPython使ってます。
● CMSへの利用 Application to CMS
● デモサイト公開! Demo site is available!
dev.s-cubism.com
ソースコードも公開もちろん無料です