valyala / ybc

Fast in-process BLOB cache with persistence support
https://groups.google.com/forum/?fromgroups=#!forum/ybc-main
Other
401 stars 43 forks source link

YBC - Yet another Blob Cache library.

This library implements fast in-process blob cache with persistence support.

===============================================================================

YBC features.

===============================================================================

Use-cases.

================================================================================

Credits.

YBC design is inspired by Varnish's "Notes from the Architect" - https://www.varnish-cache.org/trac/wiki/ArchitectNotes .

================================================================================

FAQ.

Q: Give me performance numbers! A: Well, YBC achieves 25.8 Mops/s for get() calls and 5.8 Mops/s for set() calls on my not-so-fast laptop with 2.50GHz Intel i5 CPU when running in 4 threads.

Q: Does YBC work with /dev/shm/ ? A: Yes. Just create data and index files on /dev/shm . This will completely eliminate page swapping at the cost of potential data loss on power failure or computer reboot.

Q: Is this yet another boring cache implementation? A: No. YBC is designed for modern OSes running on modern hardware. It takes advantage of OS's and computer's hardware features, while simultaneouly avoiding their weaknesses. This results in high performance and low resource usage. Read 'Features' chapter for more details.

Q: OK, how to use it in my program? A: 1. Investigate API provided by YBC at ybc.h . See tests/ folder for examples on how to properly use the API.

  1. Use this API in your program.
  2. Build either object file (ybc-[32|64]-[debug|release].o) or library (libybc-[debug|release].so) using the corresponding build target in the provided Makefile.
  3. Link the object file or library against your program.
  4. ?????
  5. PROFIT!!!

    Take a look also at bindings/ folder. It contains YBC bindings for various programming languages if you don't like programming in C. Though currently only Go is supported :)

    Other folders also worth investigation:

    • libs/ folder contains additional libraries built on top of YBC.
    • apps/ folder contains applications built on top of YBC. Currently there are the following apps here with self-describing names:
      • cdn-booster - caching HTTP proxy implementation on top of Go bindings.
      • cdn-booster-bench - benchmark tool for HTTP/1.1-compliant servers.
      • memcached - memcache server implementation on top of Go bindings for YBC. Unlike the original memcache server, it supports cache sizes exceeding available RAM by multiple orders of magnitude. It also provides cache persistence, so cached data survives server restarts or server crashes.
      • memcached-bench - benchmark tool for memcached servers. Makefile already contains build targets for all these apps.

Q: Why recently added items may disappear from the cache, while their ttl isn't expired yet? A: Because YBC is a cache, not a storage. They serve different pruposes:

Q: Can YBC cache small items, not large blobs? A: Yes. YBC works well with small items - it even supports zero-byte key and zero-byte value.

Q: Why YBC cannot adjust backing files' size on-demand? I.e. automatically shrink files when the number of items in the cache is small and automatically expand files when the number of items exceeds current files' capacity. A: Because this is stupid idea due to the following reasons:

Q: What's the purpose of cache persistence? A: Cache persistence allows skipping cache warm-up step ater the application restart. This step can be very expensive and time-consuming for large caches and slow backends. You can also make a 'golden' copy of a persistent cache and start every node in the application cluster using their own copy of the 'golden' cache, thus avoiding warm-up step on all nodes in the cluster.

Q: How well YBC performance scales on multiple CPUs? A: It scales perfectly if specially designed functions are used - ybc_config_disable_overwrite_protection(), ybc_simple_set() and ybc_simple_get().

Q: Are cache files platform-neutral? A: No. Cache files are tightly tied to the platform they were created. Cache files created on one platform (for example, x86) will be completely broken when read on another platform (for example, x64). Though it is likely they will appear as empty. So copy cache files only between machines with identical platforms.