Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
LXJS 2013: backpack — scalable photo storage
Search
Ivan Babrou
October 02, 2013
Programming
2
150
LXJS 2013: backpack — scalable photo storage
http://bobrik.name/talks/lxjs2013.pdf
— slides with notes.
http://youtu.be/T4DgxvS9Xho
— video.
Ivan Babrou
October 02, 2013
Tweet
Share
More Decks by Ivan Babrou
See All by Ivan Babrou
node.js for millions of images
bobrik
7
1.4k
Other Decks in Programming
See All in Programming
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
240
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
5.9k
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
550
선언형 UI에서의 상태관리
l2hyunwoo
0
260
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
250
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.7k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
890
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
290
iOS開発におけるCopilot For XcodeとCode Completion / copilot for xcode
fuyan777
1
1.4k
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
120
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
380
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
350
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Git: the NoSQL Database
bkeepers
PRO
427
64k
How GitHub (no longer) Works
holman
312
140k
Designing for Performance
lara
604
68k
Documentation Writing (for coders)
carmenintech
67
4.5k
The Language of Interfaces
destraynor
155
24k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
2
160
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Transcript
HI THERE, LXJS
% whoami Ian Babrou, Topface.com
60+ million users 100+ million photos
16 photos on main page up to 200 in feed
many small “previews”
This talk is about PHOTOS
Let’s look at some more numbers
12 storage nodes 70TB total space 44TB used
250 TB per month 1.6 Gbps peak 850 Mbps average
powered by node.js & nginx! open-source FTW
ARCHITECTURE aka part 1
frontend cache resizer storage
of course there are frontends, probably more than one frontend
frontend frontend frontend
round-robin dns + ipvs, probably frontend frontend frontend frontend
NGINX ngx_http_upstream_hash_module is your friend
NGINX ngx_http_upstream_hash_module because you need more than one cache, right?
#protip don’t cache anything twice
don’t do: frontend cache cache cache file#3 file#1 file#2 file#1
file#2 file#2 file#3 file#3 file#1
do: frontend cache cache cache file#3 file#1 file#2
NGINX + SSD is just great for caching, forget about
tmpfs
#protip overallocate caches
RESIZING resizing on the fly saves disk, but eats cpu
NGINX ngx_http_image_filter is your friend
BACKPACK aka part 2
first try nginx
okay for 1k files
okay for 10k files
okay for 50k files
okay until you fit in memory or have ssd
RANDOM ACCESS
DISKS ARE SPINNING
node.js to the rescue!
... and redis
... and zookeeper
simple idea: no extra fseek(3)
inspired by haystack from facebook
concatenate small files into bigger
always keep index in memory
REALIZATION ON DISK
3.5 gb files as many as you need
index for each name:offset:length name:offset:length name:offset:length
but.. no worries, this is only needed if redis goes
crazy
REALIZATION IN MEMORY
keys for files name -> file:offset:length name -> file:offset:length name
-> file:offset:length
redis 3.5gb data + index 3.5gb data + index 3.5gb
data + index memory disk all together:
POWERED BY node.js looks like webdav
PUT: 1. write data 2. write index 3. write redis
key
GET: 1. read redis key 2. read data data files
are always open!
let’s read 100K files! 0 37,5 75 112,5 150 backpack
nginx
LESS SEEKS LEAD TO BIGGER THROUGHPUT
BONUS! linearized access for processing
BUT WHAT ABOUT FUTURE?
NO MORE MEMORY vs DISK* Probably, someday.
MANAGEMENT aka part 3
1. adding servers 2. replication 3. failover
COORDINATOR
COORDINATOR combines servers into shards
COORDINATOR that’s where we need zookeeper
I KNOW let’s use DHT! like dynamo!
Rebalancing on capacity change
NO!
NO. THANK YOU!
LET’S MAKE IT SIMPLE
SHARDS (aka buckets) backpack #1 backpack #2 backpack #3 backpack
#4 backpack #5 backpack #6 shard #1 (50%) shard #2 (50%) 1:lol.jpg 2:wtf.jpg
ADDING SHARD backpack #1 backpack #3 backpack #3 backpack #4
backpack #5 backpack #6 1:lol.jpg 1:wtf.jpg shard #1 (50%) shard #2 (50%) backpack #7 backpack #8 backpack #9 50% chance shard #3 (0%)
COORDINATOR knows how to handle next file
NO REBALANCING SIMPLE
REPLICATOR
WHAT IF METEORITE WILL HIT YOUR NODE?
IT HAPPENS. YOU NEED TO ACCEPT THAT.
REPLICATOR to the rescue!
make multi-node SHARDS
DISTRIBUTE SHARDS ACROSS SERVERS
backpack #1 shard #1 lol.jpg backpack #1 lol.jpg backpack #1
lol.jpg server #1 server #1 server #1 coordinator replicator
REPLICATOR EVENTUALLY MAKES COPIES
THE WHOLE THING IS BULLET-PROOF IF YOU NEED IT
backpack #1 backpack #4 backpack #2 backpack #5 backpack #3
backpack #6 backpack #7 backpack #8 backpack #9 server #1 server #2 server #3 zookeeper #1 zookeeper #2 zookeeper #3 redis-queue #1 redis-queue #2 redis-queue #3 coordinator #1 coordinator #2 coordinator #3 replicator #1 replicator #2 replicator #3
GET THE CODE /Topface/backpack npm install backpack{,-coordinator,-replicator}
That’s it! bobrik ibobrik