Escolar Documentos
Profissional Documentos
Cultura Documentos
Scaling Storytime
April 2007
Brad Fitzpatrick
brad@danga.com
http://www.danga.com/words/
LiveJournal Overview
http://www.danga.com/words/
Stuff we've built...
● memcached ● memcached
– distributed caching – 分散型キャッシングフレーム
● MogileFS ワーク
– distributed filesystem ● MogileFS
● Perlbal – 分散型ファイルシステム
– HTTP load balancer & web server ● Perlbal
● gearman – HTTP ロードバランサー& Web
– LB/HA/coalescing low-latency
サーバー
function call “router” ● gearman
● TheSchwartz
– reliable, async job dispatch system
– 待ち時間の少ないリモート
● djabberd
ファンクションコール
– the mod_perl/qpsmtpd of ルータ
XMPP/Jabber servers
● TheSchwartz
● ..... – 非同期ジョブ管理システム
● OpenID
● djabberd
– the mod_perl/qpsmtpd of
● ...
XMPP/Jabber servers
http://www.danga.com/words/
net.
LiveJournal Backend: Today
今の LiveJournal のおおまかな構成
(Roughly.)
BIG-IP
perlbal (httpd/proxy) Global Database
bigip1 mod_perl
bigip2 proxy1 master_a master_b
web1
proxy2 web2
proxy3 Memcached
web3 slave1 slave2 ... slave5
djabberd proxy4 mc1
web4
djabberd proxy5 ... mc2 User DB Cluster 1
djabberd
web50 mc3 uc1a uc1b
mc4 User DB Cluster 2
... uc2a uc2b
gearmand
Mogile Storage Nodes gearmand1 mc12 User DB Cluster 3
sto1 sto2 gearmandN uc3a uc3b
Mogile Trackers
... sto8
tracker1 tracker2 User DB Cluster N
ucNa ucNb
MogileFS Database “workers”
gearwrkN Job Queues (xN)
mog_a mog_b theschwkN jqNa jqNb
slave1
http://www.danga.com/words/
slaveN
The plan...
http://www.danga.com/words/
Part I:
Quick Scaling History
スケーラビリティとの闘い:その歴史
http://www.danga.com/words/
Quick Scaling History
● 1 server to hundreds...
● 1 台のサーバが数百台に増えるまで
http://www.danga.com/words/
One Server
サーバ 1 台
● Simple:
● 構造は単純
http://www.danga.com/words/
Two Servers
サーバ 2 台
http://www.danga.com/words/
Two Servers - Problems
サーバを 2 台にしたときの問題
http://www.danga.com/words/
Four Servers
サーバ 4 台
● 3 webs, 1 db
● web サーバ 3 台、データベース 1 台
● Now we need to load-balance!
● 負荷分散をしよう
http://www.danga.com/words/
Four Servers - Problems
サーバを 4 台にしたときの問題
http://www.danga.com/words/
Five Servers サーバ 5 台
introducing MySQL replication
MySQL のレプリケーションを使ってみよう
● We buy a new DB ●
新しい DB サーバを買う
● MySQL replication ● MySQL のレプリケーション
http://www.danga.com/words/
More Servers
サーバの数が増えていく
わけがわからない
Chaos!
http://www.danga.com/words/
net.
Where we're at....
現状
BIG-IP
bigip1
bigip2
mod_proxy
mod_perl
proxy1
web1
proxy2
web2
proxy3 Global Database
web3
web4 master
...
web12
slave1 slave2 ... slave6
http://www.danga.com/words/
Problems with Architecture
or,
“This don't scale...”
構造的な問題(スケーラビリティがたりない)
500 reads/s
250 reads/s 250 reads/s
http://www.danga.com/words/
Eventually...
http://www.danga.com/words/
Spreading Writes
書き込みの分散
SELECT userid,
clusterid FROM
user WHERE
user='bob'
http://www.danga.com/words/
User Clusters
ユーザ別のクラスタの例
SELECT userid,
clusterid FROM
user WHERE
user='bob'
userid: 839
clusterid: 2
http://www.danga.com/words/
User Clusters
ユーザ別のクラスタの例
userid: 839
clusterid: 2
http://www.danga.com/words/
User Clusters
ユーザ別のクラスタの例
OMG i like
totally hate
my parents
userid: 839
they just
clusterid: 2
dont
understand me
and i h8 the
world omg lol
rofl *! :^-
^^;
add me as a
http://www.danga.com/words/ friend!!!
Details
詳細
http://www.danga.com/words/
Shared Storage: DRBD
http://www.danga.com/words/
Part II:
Our Software...
http://www.danga.com/words/
Caching
● caching's key to performance ● キャッシュこそがパフォーマンスの鍵
– store result of a computation or – 計算や I/O を走らせた後の結果を保
http://www.danga.com/words/
Web Load Balancing
ロードバランサー
かい技を使える
http://www.danga.com/words/
Perlbal
● Perl ● Perl
● single threaded, async event- ● シングルスレッド、非同期イベン
based トベース
– uses epoll, kqueue, etc. epoll, kqueue, etc.
–
● console / HTTP remote ● コンソール / HTTP リモートマ
management ネージメント
– live config changes – 動的設定変更
● handles dead nodes, smart ● 死んだノードを処理できる。かし
balancing こい分散
● multiple modes ● 複数のモード
– static webserver – 静的 Web サーバ
– reverse proxy – リバースプロキシ
– plug-ins (Javascript message – プラグイン (Javascript メッ
bus.....) セージバス )
● plug-ins ● plug-ins
– GIF/PNG altering, .... – GIF/PNG のパレットを変換した
り ...
http://www.danga.com/words/
Perlbal: Persistent Connections
永続的な接続
http://www.danga.com/words/
Perlbal: verify new connections
新規接続のチェックも行う
http://www.danga.com/words/
Perlbal: multiple queues
複数レベルのキュー
http://www.danga.com/words/
Perlbal: cooperative large file serving
http://www.danga.com/words/
Perlbal: cooperative large file serving
– “Friends-only” images し。
● one, clean URL ● mod_perl は認証をするだ
http://www.danga.com/words/
Internal redirect picture
http://www.danga.com/words/
MogileFS
http://www.danga.com/words/
oMgFileS
http://www.danga.com/words/
MogileFS
http://www.danga.com/words/
MogileFS: Why
http://www.danga.com/words/
MogileFS: Main Ideas
MogileFS の考え方
● files belong to classes, which ● ファイルはクラスに属している , クラス
dictate: で決めているのは :
– replication policy, min – レプリケーションポリシー , レプリカ
replicas, ... の最小数 , ...
● tracks what disks files are on ● ファイルがどのディスクにあるかを調べ
– set disk's state (up,
て
temp_down, dead) and host – ディスクの状態 (up, 一時的な down,
● keep replicas on devices on
different hosts 死亡 ) とホストをセットする
– (default class policy)
● 別のホストのデバイスにレプリカをもつ
– No RAID! (for this, for
– ( デフォルトのクラスポリシー )
databases it's good.) – RAID 不要 !
● multiple tracker databases ● 複数のトラッカーデータベース
– all share same database – トラッカーは同じデータベースクラス
cluster (MySQL, etc..) タを共有 (MySQL 他 )
● big, cheap disks ● 大きい、安いディスクを並べる
– dumb storage nodes w/ 12, – 12, 16 ディスクの大きいストレージ
16 disks, no RAID ノード。 RAID は無し
http://www.danga.com/words/
MogileFS components
● clients
● trackers
● database(s) (MySQL, .... abstract)
● storage nodes
http://www.danga.com/words/
MogileFS: Clients
● マスターがフェイルオーバーしている間のリードオンリーの
スレーブ http://www.danga.com/words/
MogileFS storage nodes
MogileFS ストレージノード
● HTTP transport
– GET
– PUT
– DELETE
● Pick a server: サーバの選択 :
– mogstored (recommended; “use Perlbal”)
● side-channel iostat interface, AIO control, ...
– Apache+mod_dav
– lighttpd
● files on filesystem, not DB ファイルシステムにファイルがあ
る、 DB ではない
– sendfile()! future: splice()
– filesystem can be any filesystem
– どんなファイルシステムでも OK
http://www.danga.com/words/
Large file
GET
request
http://www.danga.com/words/
Spoonfeeding:
slow, but event-
based
スプーンフィー
ディング : 遅い
Auth: complex, but quick けど、イベント
ベース
認証 : 複雑、でも速い
Large file
GET
request
http://www.danga.com/words/
And the reverse...
逆に ...
時間
http://www.danga.com/words/
Gearman
http://www.danga.com/words/
manaGer
http://www.danga.com/words/
Manager
dispatches work,
but doesn't do anything useful itself. :)
http://www.danga.com/words/
Gearman
http://www.danga.com/words/
Gearman Protocol
いと !:)
http://www.danga.com/words/
Gearman Uses
Gearman を使うと ...
● Image::Magick outside ● Image::Magick を
of your mod_perls! mod_perl から追い出せる !
● DBI connection pooling ● DBI 接続のプーリング
(DBD::Gofer + (DBD::Gofer +
Gearman) Gearman)
● reducing load, ●
負荷が減る、 improving
improving visibility visibility
● “services” ● サービス
– can all be in different
– can all be in different
languages, too! languages, too!
http://www.danga.com/words/
Gearman Uses, cont..
● gearmand ● gearmand
– dumb router – 頭の悪いルータ
– event-loop. Now: Perl. – イベントループ。現在 :
Future? C? Perl 。そのうち ? C?
● workers. ● workers.
– Gearman::Worker – perl – Gearman::Worker – perl
– register/heartbeat/grab jobs – ジョブの登録 / 監視 / 取得
● clients ● clients
– Gearman::Client[::Async] – Gearman::Client[::Async]
– submit jobs to gearmand – gearmand にジョブを投げる
– hash onto a gearmand – hash onto a gearmand
● optimization for coalescing ● くっつけるのに最適化し
http://www.danga.com/words/
Gearman Picture
can_do(“funcB”) can_do(“funcA”)
http://www.danga.com/words/
Gearman Misc
● Guarantees: ●
保証 :
– none! hah! :) – 無し ! hah! :)
● please wait for your ● 結果を待ってください
● クライアントが停止し
results.
● if client goes away, no ても、特に保証はな
promises い。
● No policy/conventions
● gearmand にはポリシーも
約束もない
in gearmand – 全てのポリシー / 意味は、
– all policy/meaning clients <-> workers の間
between clients <-> にある
workers ● ...
● ...
http://www.danga.com/words/
Gearman Summary
http://www.danga.com/words/
TheSchwartz
http://www.danga.com/words/
TheSchwartz
http://www.danga.com/words/
TheSchwartz uses
http://www.danga.com/words/
gearmand + TheSchwartz
http://www.danga.com/words/
djabberd
Questions to...
brad@danga.com
Software:
http://danga.com/
http://code.sixapart.com/
http://www.danga.com/words/
Bonus Slides
● if extra time
http://www.danga.com/words/
Data Integrity
http://www.danga.com/words/
Persistent Connection Woes
http://www.danga.com/words/