SERVER_ERROR object too large for cache in memcached: raise -I or chunk large values?
0 reputation · 31 May 2024, 06:21 UTC
0 reputation · 31 May 2024, 06:21 UTC
When a stored value exceeds memcached's item size limit, the text-protocol storage path rejects the write with SERVER_ERROR object too large for cache. The default limit is 1 MB, it can only be changed at daemon startup with the -I option, and the maximum permitted value is version- and build-dependent.
The unresolved decision is whether to raise -I or to keep large values under the limit by chunking or compressing them in the application. Raising the limit requires a restart, which flushes the cache and creates a cold-start load spike, and it reshapes slab-class sizing: slabs grow by page factor rather than per item, so a larger limit can increase per-allocation memory waste. Chunking avoids the restart but adds multi-key consistency and latency complexity, and client-side compression trades CPU cost for cached data that is opaque to debugging tools.
Documentation does not prescribe either approach. What workload conditions favor raising -I over application-side chunking, and what slab-level behavior would indicate that a larger item limit wastes an unacceptable amount of memory?
31275 reputation · 31 May 2024, 07:54 UTC
Neither option is universally correct — the deciding factor is the shape of your value-size distribution. If oversized values are rare outliers (a few percent of writes), keep the default 1 MB limit and fix them in the application: compress first, chunk only if compression isn't enough. If large values are the dominant shape of the workload (e.g., serialized object graphs or rendered pages that are naturally 1–5 MB) and readers need atomic single-key reads, raising -I is the cleaner choice despite the restart.
get/telnet debugging.Remember chunking's real cost: there is no atomicity across keys, and one missing or evicted chunk fails the whole value.
memcached allocates 1 MB pages and splits them into fixed-size chunks per slab class; each stored item rounds up to the next class's chunk size. A larger -I creates larger classes, and a handful of huge items can pin entire pages in a sparsely populated class. The warning signs, visible via the text protocol:
printf 'stats slabs\nstats items\n' | nc localhost 11211used_chunks and total_chunks in the largest slab classes — memory allocated but mostly empty.bytes is well below limit_maxbytes — pages are stranded in the wrong classes.If you see this, either lower -I back down, or adjust the slab growth factor (-f) so class sizes track your actual distribution more tightly.
-I for your build — it is version-dependent; run memcached -h and confirm.Assumes a mainstream memcached 1.4/1.5/1.6-era build; exact limits and stats field names should be verified against your installed version.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.