PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 12, 2022

[FIXED] How is the entry size being calculated in memcached

 November 12, 2022     memcached     No comments   

Issue

I know that entries in memcached have a length limitation by default is 1M. And this value is configurable by passing -I when starting the daemon. When I write my client, I want to protect my user from passing in values that are too large to fit in. I run some tests and found there is a 71 bytes margin on my machine between the item_size_max and key_length+value_lenght.
I have STAT item_size_max 1048576 as default,
I put in byte[] key = new byte[250]; byte[] value = new byte[1048255]; success, and 1048576-250-1048255 =71
I put in byte[] key = new byte[250]; byte[] value = new byte[1048256]; failed.
Tried with multiple total cache size, multiple max item size limitation and multiple key lengths. There is always a 71 bytes margin between the sum of the length of my key and value and the item_size_max.

I am wondering how can I figure out what is the longest value I can put in, instead of the length of the entry.

Cheers! Thanks in advance.


Solution

Got respond from github/memcached issues
https://github.com/memcached/memcached/issues/334

In short

  • there's a "./sizes" utility built which describes the overhead of various data structures.
  • A simple approach could be like setting max size to 1M - 2x the maximum key length (500).


Answered By - JasonShao
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing