You are on page 1of 76

LiveJournal: Behind The Scenes

Scaling Storytime

April 2007

Brad Fitzpatrick
brad@danga.com

danga.com / livejournal.com / sixapart.com

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. To


view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/ or send a letter to
Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

http://www.danga.com/words/
LiveJournal Overview

● college hobby project, Apr 1999 ● 大学時代のお遊びプロジェクト


● 4-in-1: ● 4-in-1:
– blogging –ブログ
– forums –フォーラム
– social-networking (“friends”) – SNS ( 友達 )
– aggregator: “friends page” + – RSS/Atom アグレゲーター
RSS/Atom ● ユーザーは1000万人強
● 10M+ accounts ● もちろんオープンソースで作成!
● Open Source! – server,
– server, – infrastructure,
– infrastructure, – original clients,
– original clients, – ...
– ...

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...

● Refer to previous presentations for more


detail...
● Questions anytime!
● Part I:
– quick scaling history
– スケーラビリティとの闘い:その歴史
● Part II:
– explain all our software
– explain all the parts!

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 台にしたときの問題

● Two single points of failure


● どっちが落ちても全部が落ちる
● No hot or cold spares
● 予備の機械がない
● Site gets slow again.
● ユーザが増えるとまた遅くなる
– CPU-bound on web node
– web サーバが CPU を食う
– need more web nodes...
– もっと web サーバが必要

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 台にしたときの問題

● Now I/O bound...



今度は I/O に時間がかかる
– ... how to use another database?
– データベースを増やそう

http://www.danga.com/words/
Five Servers サーバ 5 台
introducing MySQL replication
MySQL のレプリケーションを使ってみよう

● We buy a new DB ●
新しい DB サーバを買う
● MySQL replication ● MySQL のレプリケーション

● Writes to DB (master) データの書き込みはマスタ DB1 台


● Reads from both へ



データの読み込みは 2 台から

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...”
構造的な問題(スケーラビリティがたりない)

● DB master is SPOF ● DB のマスタが落ちるともうだめ


● Adding slaves doesn't scale ● スレーブを足してもあまり意味が
well... ない
– only spreads reads, not writes! – 読み込みだけ分散、書き込み
は分散しない

500 reads/s
250 reads/s 250 reads/s

200 write/s 200 write/s


200 writes/s

http://www.danga.com/words/
Eventually...

● databases eventual only writing


● データベースは書き込みでいっぱいっぱい
3 reads/s
3 r/s 3 reads/s
3 r/s 3 reads/s
3 r/s 3 reads/s
3 r/s 3 reads/s
3 r/s 3 reads/s
3 r/s 3 reads/s
3 r/s

400 400 400 400 400 400 400


400 write/s 400 write/s 400 write/s 400 write/s 400 write/s 400 write/s 400 write/s
write/s write/s write/s write/s write/s write/s write/s

http://www.danga.com/words/
Spreading Writes
書き込みの分散

● Our database ● DB の機械は RAID 装備


machines already did ● バックアップもとっている
RAID

ユーザのデータは 6 台以上の
スレーブにコピーがある
● We did backups ( ディスク 12 個以上 )
● So why put user data – 冗長すぎ
on 6+ slave – 全部のディスクに書く時間
ももったいない
machines? (~12+
disks)
– overkill redundancy
– wasting time writing
everywhere!
http://www.danga.com/words/
Partition your data!
データを分割しよう

● Spread your databases out, ● Spread your databases out, into


into “roles” “roles”
– roles that you never need
– それぞれが独立したデータを保

to join between ● たとえば違うユーザを違う
● different users
DB に
● or accept you'll have ● 完全に独立させられないとき

to join in app はアプリケーション側で吸収


● Each user assigned to a ● 各ユーザにクラスタ番号を割り振る
cluster number
● 各クラスタを複数の機械で構成
– クラスタの中の 2 、 3 台に書き
● Each cluster has multiple
込み( 6 台ではなくなった)
machines
– writes self-contained in
cluster (writing to 2-3
machines, not 6)
http://www.danga.com/words/
User Clusters
ユーザ別のクラスタの例

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
ユーザ別のクラスタの例

SELECT userid, SELECT ....


clusterid FROM FROM ...
user WHERE WHERE
user='bob' userid=839 ...

userid: 839
clusterid: 2

http://www.danga.com/words/
User Clusters
ユーザ別のクラスタの例

SELECT userid, SELECT ....


clusterid FROM FROM ...
user WHERE WHERE
user='bob' userid=839 ...

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
詳細

● per-user numberspaces ● ユーザごとに新たな番号を振る


– don't use AUTO_INCREMENT – MySQL の AUTO_INCREMENT
– PRIMARY KEY (user_id, は使わない
thing_id) – PRIMARY KEY (user_id,
– so: thing_id)
● Can move/upgrade users 1-at-a- – so:
time: ● 移動・変更はユーザごとにできる
– per-user “readonly” flag – ユーザごとに readonly フラグ
– per-user “schema_ver” property を立てる
– user-moving harness – ユーザごとに schema_ver を記
● job server that coordinates, 録
distributed long-lived user- – ユーザの移動をするしくみ
● 負荷の高いクライアントを
mover clients who ask for
tasks からユーザを移動させる
– balancing disk I/O, disk space ジョブサーバをつくる
– ディスク I/O やディスク容量を
均衡にできる
http://www.danga.com/words/
Shared Storage
共用ディスク (SAN, SCSI, DRBD...)

● Turn pair of InnoDB machines into a ● InnoDB を使った機械のペアをク


cluster ラスタ化
– looks like 1 box to outside world. – 外からは 1 台に見える。ひと
floating IP. つの IP が機械間を移動
● One machine at a time running fs / ● 1 台のみ FS と MySQL を運用
MySQL ● Heartbeat をもとに IP を移動、
● Heartbeat to move IP, {un,}mount ファイルシステムの { アン ,} マウ
filesystem, {stop,start} mysql ント、 {stop, start} mysql
● No special schema considerations ● 特別にスキーマを設計したりし
● MySQL 4.1 w/ binlog sync/flush なくてよい
options ● MySQL 4.1 で binlog sync/flush の
– good オプションで運用
– The cluster can be a master or – いい感じ
slave as well – クラスタはマスタにもスレー
ブにもなれる

http://www.danga.com/words/
Shared Storage: DRBD

● Linux block device driver


● Linux 上のブロックデバイスドライ
– “Network RAID 1” バ
– Shared storage without – ネットワーク上の RAID 1 と呼ば
sharing! れる
– sits atop another block – 共有ディスクではなくデータを
device 共有
– syncs w/ another machine's
– ブロックデバイスの上で動作
– ほかの機械のブロックデバイス
block device
● cross-over gigabit cable
へミラー
● クロスオーバ・ギガビット
ideal. network is faster
than random writes on ケーブルが理想。ネットワー
your disks.
クはディスクへのランダム書
● InnoDB on DRBD: HA MySQL!
き込みより速い
– can hang slaves off floater
● InnoDB と DRBD の組み合わせ:
MySQL の HA
IP
– スレーブを浮動する IP の上に置
ける
http://www.danga.com/words/
MySQL Clustering Options:
Pros & Cons
MySQL のクラスタリングの方法いろいろ・長所と短所
● no magic bullet 特効薬はない
– Master/slave
– Master/master
– DRBD
– MySQL Cluster
– ....
● lots of options! やり方はたくさん
– :)
– :(

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 を走らせた後の結果を保

I/O for quicker future access 存してあとで使う


● どこでキャッシュすべきか?
● Where to cache? – mod_perl caching
– mod_perl caching ● mod_perl 上のキャッシュはメ

● memory waste (address


モリの無駄使い
space per apache child) – shared memory
● 共有メモリは1台のマシン上で
– shared memory
● limited to single machine,
しか共有できない
– MySQL query cache
same with Java/C#/Mono ● MySQL はアップデート毎に
– MySQL query cache
ディスク I/O が走るし、容量の
● flushed per update, small
限界が小さい
max size – HEAP tables
● メモりヒープテーブルは固定
– HEAP tables
● fixed length rows, small max 長、容量の限界が小さい
size
http://www.danga.com/words/
memcached
http://www.danga.com/memcached/

● our Open Source, distributed ● オープンソースの分散型キャッ


caching system シュシステム
● run instances wherever free ● どのマシンでもいいからメモリ
memory が余ってるところで走らせれば
いい
● two-level hash ● 2 段階のハッシュ
– client hashes to server,
– クライアントはどのサーバに
– server has internal hash
接続すればよいかのハッシュ
table を持っており
● no “master node” – サーバも内部的なハッシュ
● protocol simple, XML-free テーブルを持っている
– perl, java, php, python, ruby, ● 「マスター」は存在しない
... ● シンプルなプロトコール、 XML
● popular. なんか使わないよ!
● fast.
– perl, java, php, python, ruby, ...
● 皆に好評だし
● 速い!
http://www.danga.com/words/
Perlbal

http://www.danga.com/words/
Web Load Balancing
ロードバランサー

● BIG-IP, Alteon, Juniper, Foundry ● BIG-IP, Alteon, Juniper, Foundry


– good for L4 or minimal L7 – L4 や最小限の L7 には対応し
– not tricky / fun enough. :-) ているんだけど
● Tried a dozen reverse proxies – ちょっと物足りなかった :-)
– none did what we wanted or ● リバースプロキシも色々試して
were fast enough みた
– どれもやりたかった事が実現
● Wrote Perlbal
– fast, smart, manageable
できなかったり、遅すぎたり
した。
HTTP web server / reverse ● 結果的に Perlbal を書く事に
proxy / LB – 高速で、頭が良くて、管理も
– can do internal redirects 簡単な ウェブサーバー/プ
● and dozen other tricks
ロキシ/ロードバランサー
– 内部でのリダイレクトにも対
応!
● もちろんその他に色々細

かい技を使える
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
永続的な接続

● perlbal to backends ● perlbal からアプリサーバー


(mod_perls) –アプリサーバーがいつ新しいリ
クエストを処理できるのか分
– know exactly when a かってる
connection is ready for a ● 小難しいロードバランスは

new request しないでただ次に使える接


● no complex load balancing ● 続を使う
クライアント側も永続的な接続を
logic: just use whatever's 使う。でもアプリサーバと永続的
free. beats managing に接続をするとは限らない
“weighted round robin” hell.
● clients persistent; not tied
to backend

http://www.danga.com/words/
Perlbal: verify new connections
新規接続のチェックも行う

● connects often fast, but ● アプリサーバが接続に応答し


ても、カーネルに接続してい
talking to kernel, not るだけで Apache が応答し
apache (listen queue) たとは限らない
– send OPTIONs request – OPTION リクエストを投
to see if apache is there げて、 Apache が応答して
● Huge improvement to いるか確認する
user-visible latency!

http://www.danga.com/words/
Perlbal: multiple queues
複数レベルのキュー

● high, normal, low priority (idle, bots) queues


● キューの優先度が高いものから低いもの(ボットや待機状態の
もの)

http://www.danga.com/words/
Perlbal: cooperative large file serving

● large file serving w/ ● mod_perl で大きいファイ


mod_perl bad... ルを送信するのは良くない
– mod_perl サーバーには
– mod_perl has better
データをそのまま送るよ
things to do than うな簡単な仕事よりもっ
spoon-feed clients と重要な事をしてもらい
bytes たい

http://www.danga.com/words/
Perlbal: cooperative large file serving

● internal redirects ● 内部リダイレクト


– 大きいファイルは Perlbal に
– mod_perl can pass off
処理してもらう
serving a big file to ● ディスクからでも、他の

Perlbal URL からでも


● either from disk, or from – クライアント自体はリダイレ
other URL(s) クトされたとわからない
– 例えば友達しか見れない画像
– client sees no HTTP
とか
redirect ● 変な URL を使う必要な

– “Friends-only” images し。
● one, clean URL ● mod_perl は認証をするだ

● mod_perl does auth, and け


● 画像自体は perlbal が処理
is done.
● perlbal serves. する

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

● our distributed file ● 分散ファイルシステム


● オープンソース
system ● ユーザースペース
● open source ● 同様の仕組み
– Google GFS
● userspace – Nutch Distributed File
● hardly unique System (NDFS)
– Google GFS ● 製品レベルの品質
– Nutch Distributed File – ユーザーも多い
System (NDFS)
● production-quality
– lot of users

http://www.danga.com/words/
MogileFS: Why

● alternatives at time were ● 開発前の選択肢はいずれも


either: – クローズドな , 今までに
– closed, non-existent, ない , 高価な , 開発中の ,
expensive, in 複雑な ...
development, complicated, – データのリカバリが恐ろ
... しい / 不可能
● 新しい、普通でない、
– scary/impossible when it
came to data recovery 考え抜かれていない
● new/uncommon/
ディスク上のフォー
マット
unstudied on-disk ● 簡単だったから
formats – 最初のバージョン = 週末
● because it was easy で完成
– initial version = 1 weekend

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

● tiny text-based protocol 小さい、テキストベースのプ


ロトコル
● Libraries available for: 使えるライブラリ :
– Perl
● tied filehandles (tie されたファイルハンドル )
● MogileFS::Client
– my $fh = $mogc->new_file(“key”, [[$class], ...])
– Java
– PHP
– Python?
– porting to $LANG is be trivial 移植は簡単
future: no custom protocol. only HTTP PUT to trackers

● doesn't do database access データーべースアクセス


不要
http://www.danga.com/words/
MogileFS: Tracker
(mogilefsd)
● The Meat 心臓部
● event-based message bus イベントベースのメッセー
ジバス
– load balances client requests, world info クライアン
トの要求を負荷分散する、 world info
● process manager プロセスマネージャー
– heartbeats/watchdog, respawner, ...
● Child processes: 子プロセス
– ~30x client interface (“query” process)
● interfaces client protocol w/ db(s), etc
– ~5x replicate
– ~2x delete
– ~1x monitoring
http://www.danga.com/words/
– ....
Trackers' Database(s)
トラッカーのデータベース

● Abstract as of Mogile 2.x // Mogile 2.x 時点の抜粋


– MySQL
– SQLite (joke/demo)
– Pg/Oracle coming soon?
– Also future: これもそのうち :
● wrapper driver, partitioning any above

– small metadata in one driver (MySQL Cluster?),


– 一つのドライバに小さいメタデータ (MySQL Cluster?),
– large tables partitioned over 2-node HA pairs
– 2 ノードの HA ペア上のパーティション分けされた大きい
テーブル
● Recommend config: 推奨設定
– 2xMySQL InnoDB on DRBD
– 2 slaves underneath HA VIP //HA の大物の下に、 2 つのスレーブ
● 1 for backups 一つはバックアップに

● read-only slave for during master failover window

● マスターがフェイルオーバーしている間のリードオンリーの

スレーブ 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...
逆に ...

● Now Perlbal can buffer ● Perlbal はアップロードを


uploads as well.. バッファできるが ...
– Problems: – 問題 :
● LifeBlog uploading ● 日記ブログのアップロー

– cellphones are slow ド


● LiveJournal/Friendster – 携帯電話は遅い
● LiveJournal/Friendster の
photo uploads
– cable/DSL uploads still 写真アップロード
slow – ケーブル /DSL アップ
– decide to buffer to “disk” ロードもまだ遅い
(tmpfs, likely) – “disk” にバッファすること
● on any of: rate, size, time に決めた (tmpfs が有望 )
● いずれも : rate, サイズ、

時間
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

● low-latency remote function call ● 待ち時間の少ないリモート


“router” ファンクションコール
● client wants results. arguments ルータ
to submit a job: ● クライアントは結果がほし
– opaque bytes: “function い。引数にジョブをあたえる :
name” – 第一引数に 関数名
– opt. opaque: “function args” – ( オプション ) 第二引数
(Storable, ...) に 関数の引数
– opt. coalescing value (Storable, ...)
● can multiplex results of – ( オプション ) 値をくっつ
slow call back to multiple ける
● 複数の待っているクラ
waiting callers
イアントへ、複数の遅
延コールバックの結果
を多重送信できる

http://www.danga.com/words/
Gearman Protocol

● binary protocol ● バイナリプロトコル


– future: C server / client. – 将来 : C サーバ / クライアン
– currently: gearmand doesn't ト
use much CPU – 現在 : gearmand は CPU をそ
● solution: we need to push
んなに使わない
it harder! :) ● 解決 : もっと使い倒さな

いと !:)

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..

● running code in ● 並列にコードが動く


– 一回で 10 のデータベース
parallel に問い合わせる
– query ten databases at ● イベントループからブロッキ
once ングコードを実行
– POE/Danga::Socket ア
● running blocking code
プリケーションから DBI
from event loops を
– DBI from ● イベントループデーモンから
POE/Danga::Socket CPU を拡散する
apps
● spreading CPU from
ev loop daemons
http://www.danga.com/words/
Gearman Pieces

● 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 ● くっつけるのに最適化し

● can use any on failure ている


● 失敗時に何でも使える

http://www.danga.com/words/
Gearman Picture

gearmand gearmand gearmand


g”)
, “ar
cA”
“fun
call(

can_do(“funcB”) can_do(“funcA”)

client worker worker

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

● Gearman is sexy. ● Gearman はセクシー


– especially the – 特に、 coalescing
coalescing ●
チェック !
● Check it out! – これはちょっとあんまり宣

– it's kinda our little 伝してない秘密


● やばい、秘密を漏らし

unadvertised secret ちゃったかな ?


● oh crap, did I leak the
secret?

http://www.danga.com/words/
TheSchwartz

http://www.danga.com/words/
TheSchwartz

● Like gearman: ● Like gearman


– job queuing system ● 頼できるジョブのキューシ
– opaque function name ステム
● 現在はライブラリ、ネット
– opaque “args” blob ワークサービスではない
– clients are either:
● submitting jobs
● workers
● But not like gearman:
– Reliable job queueing
system
– not necessarily low latency
● currently library, not network
service
http://www.danga.com/words/
TheSchwartz Primitives

● insert job ● ジョブの挿入


● ジョブを つか
● “grab” job (atomic む (atomic grab)
grab) – 'n' 秒間
– for 'n' seconds. ● ジョブに終わった印を付ける
● mark job done ● 一時的な失敗
– 備考や再スケジュール
● temp fail job for future ● 一つ以上の他のジョブへリプ
– optional notes, レース
– アトミック
rescheduling details..
● replace job with 1+
● ...
other jobs
– atomic.
● ...
http://www.danga.com/words/
TheSchwartz

● backing store: ● ストレージ


– データベース
– a database – uses Data::ObjectDriver
– uses Data::ObjectDriver ● MySQL,
● MySQL, ● Postgres,
● Postgres, ● SQLite,
● SQLite, ● ....
● ....
but HA: you tell it @dbs,

● but HA: you tell it @dbs,
and it finds one to insert
and it finds one to insert
job into
job into – likewise, workers foreach
– likewise, workers foreach (@dbs) to do work
(@dbs) to do work

http://www.danga.com/words/
TheSchwartz uses

● outgoing email (SMTP client) ● メール配信 (SMTP クライアント )


– millions of emails per day – 一日に数百万のメール
● LJ notifications
● LiveJournal の通知
– ESN: イベント (Event) 、サブス
– ESN: event, subscription,
クリプション (Subscription) 、通
notification 知 (Notification)
● one event (new post, etc)
● あるイベント ( 新しい投稿な

-> thousands of emails, ど ) -> 数千のメール、ショー


SMSes, XMPP messages, トメッセージ、 XMPP メッ
etc... セージ、他
● pinging external services ● 他のサービスへの ping
● atomstream injection ● atomstream の挿入
● ..... ● 数十のユーザー
● dozens of users
● TypePad, Vox, LiveJournal で共有の
ファーム
● shared farm for TypePad, Vox, LJ

http://www.danga.com/words/
gearmand + TheSchwartz

● gearmand: not reliable, ● gearmand: 保証無し、少


low-latency, no disks ない待ち時間、ディスク不要
● TheSchwartz: latency,
● TheSchwartz: 待ち時間、
信頼できる、ディスクを使う
reliable, disks ● TypePad では :
● In TypePad: – Gearman が
– TheSchwartz, with TheSchwartz ワーカーを
gearman to fire off 起動させる
TheSchwartz workers. ● ディスクを使うが、待ち

● disks, but low-latency 時間は少ない


● そのうち : ディスクを使
● future: no disks,
SSD/Flash, MySQL わずに、
SSD/Flash 、 MySQL
Cluster
Cluster
http://www.danga.com/words/
djabberd

http://www.danga.com/words/
djabberd

● Our Jabber/LJTalk ● Our Jabber/LJTalk


server server
● S2S: works with ● S2S: works with
GoogleTalk, etc GoogleTalk, etc
● perl, event-based ● perl 、イベントベース (epoll
(epoll, etc) など )
● done 300,000+ conns ● 300,000 以上の接続を行う
● tiny per-conn memory ● 接続ごとのメモリのオーバー
ヘッドが小さい
overhead – 可能なら、 XML パーサー
– release XML parser の状態を更新する
state if possible
http://www.danga.com/words/
djabberd hooks

● everything is a hook ● 全てはフック


– 認証だけでない ! 全部
– not just auth! like,
– mod_perl や qpsmtpd な
everything.
どのように
– ala mod_perl, qpsmtpd, – ノード間のコミュニケー
etc. ション
– inter-node ● 非同期のフック
communication – use
● async hooks Gearman::Client::Async
– Danga::Socket ベースの
– use アプリ用の非同期の
Gearman::Client::Async Gearman クライアント
– async Gearman client
for Danga::Socket-
based apps
http://www.danga.com/words/
Thank you!

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

● Databases depend on fsync()


– but databases can't send raw SCSI/ATA commands
to flush controller caches, etc
● fsync() almost never works work
– Linux, FS' (lack of) barriers, raid cards, controllers,
disks, ....
● Solution: test! & fix
– disk-checker.pl
● client/server
● spew writes/fsyncs, record intentions on alive machine,
yank power, checks.

http://www.danga.com/words/
Persistent Connection Woes

● connections == threads == memory


– My pet peeve:
● want connection/thread distinction in MySQL!
● w/ max-runnable-threads tunable
● max threads
– limit max memory/concurrency
● DBD::Gofer + Gearman
– Ask
● Data::ObjectDriver + Gearman

http://www.danga.com/words/

You might also like