44
DIFF法: テキスト、 ファイルシステム バイナリ差分 Marat Zhanikeev [email protected] maratishe.github.io 2015/01/10 Cloudyiizuka

DIFF法:テキスト・ファイルシステム・バイナリ差分

Embed Size (px)

Citation preview

DIFF法: テキスト、 ファイルシステム … バイナリ差分

Marat Zhanikeev [email protected]

maratishe.github.io

2015/01/10

Cloudy@iizuka

.

maratishe.github.io

diffとpatchの考え方

• AとBの差分をとって、DIFFファイルで保存する

• AとDIFFを使って、Bファイルを再現する(Aをパッチするという)

• あるDIFFツールは、diffとpatch、両方の機能をもっている

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 2/44...

2/44

.

maratishe.github.io

標準(テキスト)diff

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 3/44...

3/44

.

maratishe.github.io

標準のDIFF

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 4/44...

4/44

.

maratishe.github.io

標準のDIFF: Nice!

• チームワークがスムーズに行けた方

• みんなが嬉し

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 5/44...

5/44

.

maratishe.github.io

標準のDIFF: 衝突!

• PULLせずにPUSHすれば、ぶつかる可能性がある

• チームの中で、一番苦しむこと• 衝突回避の方法は?

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 6/44...

6/44

.

maratishe.github.io

標準のDIFF: まとめ

• diffは一行の単位で働く

• x行からy行が更新されたという記録なので、衝突が反応しやすい

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 7/44...

7/44

.

maratishe.github.io

Docker型(ファイルシステム)DIFF

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 8/44...

8/44

.

maratishe.github.io

Docker : ファイルシステムDIFF

• Dockerの商品:コンテナ=OSイメージ =ファイルシステム

• Dockerの大問題:量、大量のトラヒック• Dockerの解決:LAYERS = 階層化• Dockerの技術:Git/Githubそのまま

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 9/44...

9/44

.

maratishe.github.io

Docker: Dockerfile (FROMコマンド)

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 10/44...

10/44

.

maratishe.github.io

Docker: トラヒック量

• 数分かかるから、マイグレーションの柔軟性に限りがある

• マイグレーションの面、Dockerの動作がマニュアルなので、その限りも

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 11/44...

11/44

.

maratishe.github.io

Docker大問題とその解決へ向けた技

• 1アカウントに、(無料で)1レポの限定• ストーレジ節約:95%のDockerユーザがDockerカウントを持っていない

◦ Dockerfileで十分に対応できる◦ PUSHする必要のある時だけにアカウントをつくる

• アカウントを持っていないなら、FROMを使うしかない◦ FROM+alphaでアプリを構築する(との考え)

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 12/44...

12/44

.

maratishe.github.io

バイナリDIFF

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 13/44...

13/44

.

maratishe.github.io

標準のDIFF → バイナリDIFF

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 14/44...

14/44

.

maratishe.github.io

バイナリDIFFの手に入りやすさ

• The VCDIFF Generic Differencing and Compression Data Format, (RFC3284)• xdeltaコマンドライン http://xdelta.org

• xdelta以外にいくつかのツールがあるが、妥当性でxdeltaに負ける

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 15/44...

15/44

.

maratishe.github.io

Xdelta in Action

• 適当に、いくつかのバイナリDIFF事例

• .xvaに注目

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 16/44...

16/44

.

maratishe.github.io

バイナリDIFF性能

Application or Filetype Filesize Diffsize Diff %SC: Source Code (1min auto-save) ~40kb 0.2kb 0.5%

PPT: Power Point 100kb 10kb 10%DOC: Word Document 60kb 5kb ~10%

PDF: PDF Annotation 100kb 2kb 2%ZIP: Archive (Github commits/exports) 2Mb 2kb 0.01%

VM1: VM Images (xva, small) 800Mb 150Mb 20%VM2: VM Images (xva, large) 2Gb 200Mb 10%

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 17/44...

17/44

.

maratishe.github.io

Xdelta man page

• diffとpatchはもちろんのこと• mergeの機能が面白い -- 詳しく後で

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 18/44...

18/44

.

maratishe.github.io

バイナリDIFFの活用化(の事例探し)

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 19/44...

19/44

.

maratishe.github.io

バイナリDIFFが活用されていますか?

• (テキスト) DIFF?• git/github?• Docker?• GoogleDrive, Dropbox, ...?

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 20/44...

20/44

.

maratishe.github.io

GDrive: Probing

… Slave

Cloud Drive

Clients Probe

Traffic Filesystem

Master

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 21/44...

21/44

.

maratishe.github.io

GDrive: File Sync Traffic

0 0.15 0.3 0.45 0.6 0.75 0.9 1.05 1.2File lifespan (hours)

0

120

240

360

480

Traf

fic v

olum

e (k

byte

s) • 何かへんーすね、トラヒック量が増えているんじゃん!

• ちなみに、diffで確認したところ、細かい差分のみのことが確かめてある!

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 22/44...

22/44

.

maratishe.github.io

GDrive: File Sync Traffic

0 5 10 15 20 25 30 35File ordered by increasing size

-0.75-0.5

-0.250

0.250.5

0.75

ccf (

traffi

c vo

lum

e vs

tim

e)

Per file CCF

0:50 50:100 100:500 500:1000 1000:100000

-0.060

0.060.120.180.240.3

0.36

ccf (

traffi

c vo

lum

e vs

tim

e)

Per class CCF

Class (min:max volume in kbytes)

• データが汚いけど、ファイルサイズで集合して、CCFをかけると、トラヒック量とファイルサイズの2つの傾向が同一のものであることが分かる

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 23/44...

23/44

.

maratishe.github.io

バイナリDIFFが活用されていますか?

• (テキスト) DIFF?• git/github?• Docker?• GoogleDrive, Dropbox, ...?

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 24/44...

24/44

.

maratishe.github.io

DiffHubのアイディア

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 25/44...

25/44

.

maratishe.github.io

Traditional vs Efficient vs DiffHub

Cloud Drive

User A

User B

New

Old

Old

Diff Diff

Old version New version Binary diff

DiffHub

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 26/44...

26/44

.

maratishe.github.io

クラウド上のチーム開発?

• PUSHより細かい単位でファイル同期する(autosaveでもよい)

• 主な利点:衝突にすぐに気づく• ところで:Cloud Drive上でバージョン管理がすでにある!

◦ APIを使って衝突回避の技術が作れる

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 27/44...

27/44

.

maratishe.github.io

Cloud Driveの動作(と待ち時間)

1. ファイル同期 (file sync)

2. (新規)クライアント追加

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 28/44...

28/44

.

maratishe.github.io

DiffHub: クライアント追加

DiffHub

Existing Client(s)

Master Copy

New Client

Register 1

2 Notify 3

3 v0 diff

P2P Sync

• DiffHubがファイルをもっていない!

• 解決1: v0diff (ファイル全体が差分である)

• 解決2: P2P型同期

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 29/44...

29/44

.

maratishe.github.io

DiffHub: P2P型同期の2種類

VMpopulation

CurrentSources

ServiceProvider

(SP)

Tracker

ServiceProvider

(SP)

Parentpeers

P2Pstreaming

Cloudstreaming

ClientClient

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 30/44...

30/44

.

maratishe.github.io

DiffHub: バージョン管理

• MD5でバージョンを特定する◦ 旧バージョン + 新バージョンの2つのMD5

• バージョン更新に必要なDIFF

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 31/44...

31/44

.

maratishe.github.io

バイナリDIFFの性能

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 32/44...

32/44

.

maratishe.github.io

Binary vs Text Diff

0 5 10 15 20 25 30 35 40Ordered list (decreasing filesize)

1.5

2.5

3.5

4.5

5.5

6.5

File

- and

diff

-size

(log

of b

ytes

)

File sizeBinary diff

0 5 10 15 20 25 30 35 40Ordered list (decreasing binary diff size)

1.5

2

2.5

3

3.5

4

Diff

size

(log

of b

ytes

)

Binary diffText diffCompressed text diff

• ファイルサイズに依存しない(更新量がメイン)• たまに、テキストDIFFより有利• テキストDIFFを圧縮することに効果が殆ど無い

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 33/44...

33/44

.

maratishe.github.io

GDrive: HotSpot分布

0 10 20 30 40 50Ordered lists

0

0.6

1.2

1.8

2.4

3

3.6

4.2

4.8

5.4

log(

1 +

file

size)

pophotflashMagnitude(5) Variance(2)

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 34/44...

34/44

.

maratishe.github.io

GDrive: DiffHub性能

0 10 20 30 40 50Ratio of updated files (%)

0

0.35

0.7

1.05

1.4

1.75

2.1

2.45

2.8

Ave

rage

wai

ting

time

(log

of se

cond

s)

TraditionalDiffHub1,

31,

51,

71,

10 3,3

3,5

3,7

3,10 5,3

5,5

5,7

5,10 7,3

7,5

7,7

7,10

10,3

10,5

10,7

10,1

0

0

0.5

1

1.5

2

2.5

Ave

rage

wai

ting

time

(log

of se

cond

s)

Hotspot setup (Magnitute, Variance)

15% diff10% diff

5% diff

• 実運用データ(上部):10倍の効果• HotSpot分布をもとにしたシミュレーションデータ(下部):15~20倍の効果

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 35/44...

35/44

.

maratishe.github.io

DiffHubの活用化

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 36/44...

36/44

.

maratishe.github.io

DiffHub + GoogleDrive

• GDrive上エミュレーションAPPは実装済み

• GDrive空間+ローカルファイル空間に分解

• GDrive空間:DIFFファイル(+MD5などのメタ)のみ

• ローカル空間:ファイル自体• 利点: GDrive容量10倍増加、同時待ち時間15倍低下

• 欠点: 新規クライアントの問題がまだです(v0diff方法は完成)

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 37/44...

37/44

.

maratishe.github.io

DiffHub + Docker (思い出し)

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 38/44...

38/44

.

maratishe.github.io

DiffHub + Docker(思い出し)

• ユーザ側でマイグレーションを管理することが出来るので、 herokuより柔軟

• コンテナ管理、インストール、実行は、全部ユーザ側で実行

• 柔軟性として、AWS ... Docker ...Herokuのスケールの中で、真ん中に入る

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 39/44...

39/44

.

maratishe.github.io

DiffHub + Docker(更新後)

• HAVEコマンド◦ ローカルでもっているイメージのリスト

• NEED(FROMと同じ機能)

• 動き: Dockerが、HAVEの中で一番近いDIFFを送ってくれる

• 利点: トラヒック10倍以上節約の可能性

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 40/44...

40/44

.

maratishe.github.io

DiffHub + Docker: Dockerfile

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 41/44...

41/44

.

maratishe.github.io

DiffHub + Docker: (new) Dockerfile

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 42/44...

42/44

.

maratishe.github.io

議論の課題

• バイナリDIFFの使用方法として、他に何が考えられますか?

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 43/44...

43/44

.

maratishe.github.io

That’s all, thank you ...

M.Zhanikeev -- [email protected] DIFF法:テキスト・ファイルシステム・バイナリ差分 -- bit.do/marat140110 44/44...

44/44