Sizing and what to watch

Start with the defaults and watch the counters of Yac::info — they accumulate from start_time, so compare two snapshots taken some time apart:

  • hit rate healthy (say >= 90%): the cache is fine; nothing to do, whatever the other counters show;
  • hit rate low and kicks climbing: the key pool is too small for the key set — live entries get evicted before they are re-read. Raise yac.keys_memory_size;
  • recycles frequent: this is a real problem, not a benign counter. A recycle means the value allocator has wrapped and is about to overwrite entries — anything overwritten dies before it could be re-read, so the bytes spent storing it were wasted and the hit rate suffers. The value pool is too small for the volume of live data. In order of impact:

    • give entries a TTL. Values written with ttl = 0 stay live forever, so they keep occupying the pool and force the cursor to wrap sooner. A TTL bounds how long each entry may live, shrinking the live working set the pool has to hold;
    • raise yac.values_memory_size so the pool holds the whole live value set (remember to budget roughly twice the live footprint — a value only dies once the cursor comes back around to overwrite it);
    • store less per entry: lower yac.compress_threshold if it is set above the 1024 minimum, so large payloads are compressed, and trim values that do not need to be cached in full;

  • fails growing: values that could not be stored, most often a single value larger than the 1 MB stored-size limit even after compression — split the value.