2009年5月2日土曜日

facebook needle

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
haystack @ facebook engineering blogを読んだときのメモ。


The Photos application is one of Facebook’s most popular features. Up to date, users have uploaded over 15 billion photos which makes Facebook the biggest photo sharing website. For each uploaded photo, Facebook generates and stores four images of different sizes, which translates to a total of 60 billion images and 1.5PB of storage. The current growth rate is 220 million new photos per week, which translates to 25TB of additional storage consumed weekly. At the peak there are 550,000 images served per second. These numbers pose a significant challenge for the Facebook photo storage infrastructure.


needle以前の構成

  • * Upload tier receives users’ photo uploads, scales the original images and saves them on the NFS storage tier.
    アップロードを受け取ってNFSに書き込む層

  • * Photo serving tier receives HTTP requests for photo images and serves them from the NFS storage tier. HTTPリクエストを受け取ってNFSから画像を読み出して返す層

  • * NFS storage tier built on top of commercial storage appliances. 一般商用ストレージの上に構築されたNFS層。


NFSのmetaデータ読み出しがbottle neckになった。対策としてはCDNを使ったり、NFSのfile handleをcacheしたりしていた。

で、新しいheystackはどういう構成かというと

The new photo infrastructure merges the photo serving tier and storage tier into one physical tier. It implements a HTTP based photo server which stores photos in a generic object store called Haystack. The main requirement for the new tier was to eliminate any unnecessary metadata overhead for photo read operations, so that each read I/O operation was only reading actual photo data (instead of filesystem metadata). Haystack can be broken down into these functional layers

Haystackという汎用objectサーバを用意した。メタデータは読まない。リクエストしたらデータ自体を返す。

5つの機能からなる。

  • HTTP server

  • Photo Store

  • Haystack Object Store

  • Filesystem

  • Storage



Storage


10TBの容量が手に入る。2U storage blade。ハード構成なので割愛。

* 2 x quad-core CPUs
* 16GB – 32GB memory
* hardware raid controller with 256MB – 512MB of NVRAM cache
* 12+ 1TB SATA drives

raid6. raidカードのcacheはwrite用に使う。hddのキャッシュは殺してある。

File System


XFSだそうだ。extent baseなFile Systemはブロックを連続配置しやすいので、保存のためにブロックを複数必要とする画像ばっかりもつような用途では、有利ということらしい。

haystack



Haystack is a simple log structured (append-only) object store containing needles representing the stored objects. A Haystack consists of two files – the actual haystack store file containing the needles, plus an index file. The following figure shows the layout of the haystack store file:

Haystack = index file + needle file
needleは物理的に上書きされない。論理的に上書きされる。(同じkeyを持つneedleがappendされるとそちらが見えるようになる)


The main purpose of the index is to allow quick loading of the needle metadata into memory without traversing the larger Haystack store file, since the index is usually less than 1% the size of the store file.

index fileはメモリ上に持っておく。実体にはoffsetでアクセス。

データ書き込みは、データを同期で書き込んで、indexをあとから非同期で書き込む。indexは時々hddに書き込んであげる。クラッシュしたときはlast valid needle(推定するにまともにindexが保持されている範囲)まで、needle fileを読み進んでそこからindexに対して非同期書き込みを再開する。

空き領域はコンパクションをして回収。コンパクションとはdeleteやduplicatedな領域をskipしながらcopyすること。

Photo Store


needleのidをon memoryでもっている。scale済みを持つようにしている。

HTTP server


I/Oバウンドなので特になし。

0 件のコメント: