Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
4.1.3 ThriftとProtocol Buffers
Search
koyamaso
April 22, 2021
56
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
4.1.3 ThriftとProtocol Buffers
「データ指向アプリケーションデザイン」輪講資料
koyamaso
April 22, 2021
More Decks by koyamaso
See All by koyamaso
9.4.3 耐障害性を持つ合意
koyamaso
0
34
5.4 リーダーレスレプリケーション
koyamaso
1
220
spack.yamlを書こう
koyamaso
0
95
Raft 文献調査
koyamaso
0
190
主専攻実験S-3 メタヒューリスティクスと巡回セールスマン問題 最終発表
koyamaso
0
480
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
530
New Earth Scene 8
popppiees
3
2.5k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
How to make the Groovebox
asonas
2
2.4k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Transcript
データ指向 アプリケーションデザイン 4.1.3 ThriftとProtocol Buffers
Apache Thrift https://thrift.apache.org/ 「スケーラブルな言語間サービス開発」のためにFacebookにて開発された 遠隔手続き呼び出し (RPC) フレームワーク .thriftファイルにRPCを定義し、それをもとにやり取りする 対応言語: C++,
Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages. 今回はサーバをNodejs,クライアントをRustにしてping pongしてみる
.thrift ファイルを書き、コードを生成 コード生成(Rust) コード生成(Nodejs)
Thriftのネットワークスタック - Protocol 例: Binary,Compact, JSON - Transport 例: Buffered,
Framed
実装 protocolとtransportを揃える
Protocol: Binary, Transport: Buffered
Protocol: Binary, Transport: Framed
Protocol: Compact, Transport: Framed
82 21 02 04 70 69 6e 67 18 04
70 69 6e 67 00 4文字 Compact Protocolでエンコードされたものを読む 第一引数”ping”“\0” 終端を表す 4文字 rpc名”ping” 0 0 0 1 1 0 0 0 フィールドタグ1 種類8(文字列)
スキーマの進化と互換性 スキーマで重要なものは - rpcの名前 - フィールドタグ番号とその型 だとわかった 前方互換性及び後方互換性を保ったままスキーマを変更したい 前方互換性 :古い製品がより新しい製品の機能やデータ形式を扱うことができること
後方互換性 :新しい製品が古い製品の機能やデータ形式を扱うことができること
フィールドタグとスキーマの進化 必須ではない(もしくは初期値が設定できる)フィールドを追加すればよい そのフィールドには新しいフィールドタグ番号を割り当てる - 古いシステムが新しいスキーマを読む場合(前方互換性) 知らないフィールドタグ番号はスキップされるので問題ない - 新しいシステムが古いスキーマを読む場合(後方互換性) 新しいフィールドは必須ではないので問題ない
データ型とスキーマの進化 Thriftのドキュメントを調べた限り 型を変更してもキャストされるとは書いていないので、 スキーマの型を変更するのはやめたほうがよさそう 新しいフィールドタグ番号を割り当てた、別のフィールドを用意したほうが良い
Appendix 以降、Protocol Buffers ( https://developers.google.com/protocol-buffers/ )の説明 gRPC ( https://grpc.io/ )
はProtocol Buffersを使うRPCフレームワーク gRPCは比較的有名なフレームワークだが、今回は紹介せず、 Protocol Buffers のみ紹介する
Protocol Buffers https://developers.google.com/protocol-buffers 構造化されたデータを シリアライズ・デシリアライズするライブラリ .protoファイルに構造化されたデータを記述する Goの場合 を実行してコードを生成する
Protocol Buffersを使ったシリアライズ 実行結果 “Taro” “
[email protected]
” 1 4 13 0 0
0 0 1 0 1 0 フィールドタグ1 種類2(文字列)