Skip to content
Son's blog
All writing

Finding Needle in Haystack

Paper notes · Source updated

Finding Needle in Haystack

Summary

problems with serving photos with NFS approach

  1. wasted storage for not-used dir and file metadata (posix file system)
  2. requires to load metadata into mem first to then load file itself from disk. This results in more disk IOs for file read.

solution

result

design requirements

  1. high throughput low latency
  2. fault-tolerant
  3. more cost-effective than building for NAS
  4. simple

2-Previous Design

What did not work in NFS design?

  1. CDN misses the long-tail requests (older, less common photos) - typical for Facebook photos usage - which result in high latency. This is bad for user experience.
  2. Caching all in CDN is not cost effective.
  3. Having enough RAM to cache all the inodes (~256 bytes each) is also not cost effective.

1 photo = 1 file = 1 inode = hundred of bytes

3-Haystack design

Haystack solves the solution by

  1. reducing the amound of metadata per photo to keep all the metadata in memory.
  2. storing multiple photos in a very large file to reduce metadata further.

This then reduces the disk operations that the storage systems need when doing a read. Using the typical POSIX inode design the amount of memory needed is 256 bytes * 2B * 1000 = 512TB for metadata alone.

System components

  1. Store: persistent storage system, manages fs metadata for photos.
  2. Directory: maintains logical to physical mapping and application metadata (how to construct the photo URL for app to access).
  3. Cache: internal CDN provides shield Store against CDN failure and frequent requests.

Haystack Directory

http://<CDN>/<Cache>/<machine id>/<logical volume, photo>

Haystack Cache

Haystack Store

Key design decision: metadata operations (getting filename, location, offset, size) do not need disk IO.

Design

To get needle quickly

Detailed designs of

Photo Read

Photo Write

Photo Delete

Index File

Design decisions: async index updates to reduce write latency

  1. write photo: sync append needle to volume, async append index
  2. delete photo: async set flags in needle, not updating index

Side effects to be tackled

  1. needles can exist without corresponding index records
  2. index records do not reflect deleted photos

Filesystem

Recovery from failures

Failures to tolerate: faulty hard drives, bad RAID controllers, bad motherboards, etc.

How?

  1. detection
    1. background job pitch-fork periodically checks health of Store machines.
    2. mark read-only if any problem and alert for intervention.
  2. repair:
    1. investigate and fix offline or
    2. bulk-sync op to reset a Store machine using a replica

Optimizations

  1. compaction
  2. reducing 20% mem footprints reduce
    • 10 bytes of memory/ photo (instead of 536 bytes of xfs_inode_t in Linux with 1 file/photo per inode metadata)
    • replacing delete flag by setting offset 0
    • not keeping track of cookies in memory
  3. batch upload
    • because big sequential writes is more suitable for disks than small random writes.
    • applies well to Facebook because users usually upload entire albums instead of single pictures.
    • improvements of aggregating writes result below.

4-Evaluation

Contents

  1. look at Facebook photo requests workload
  2. show Directory effect
  3. show Cache effect
  4. show Store effect in synthetic and production workloads

Tools

Distribution

Traffic volume

Haystack Directory: balances reads and writes across Store node well as shown in Fig 8.

Haystack Cache: hit rate of 80% shows that it effectively reduces workloads for write-enabled Store.

Haystack Store

Fig10

Fig11 prod avg latency of read and write nodes in fig10

Refs