Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the limit of number of keys I can multi-get on memcache

Tags:

php

key

memcached

So in PHP we can do $memcache->get(array('a','b','c'));
I wonder what is the limit of keys before things break. Can I pass 1000 keys? 10000 keys?

I tried to find answer, but can't find anywhere.

Is there someone who have experience in passing large number of keys to do multi-get to memcache?

like image 367
shendz Avatar asked Mar 17 '11 19:03

shendz


People also ask

What is the maximum key size in memcached?

The maximum length of the key in Memcached has a restriction of 250 bytes.

How do I view memcached data?

Memcached get command is used to retrieve the value stored at key. This command takes one or more keys and returns all found items. If the key does not exist in Memcached, then it will return nothing.


2 Answers

The Memcached extension supports at least 100,000 keys in a getMulti, given this test:

php > $data = array_map(function($v){ return 'x' . $v; }, range(1, 100000));
php > foreach($data as $d) { $memcached->add($d, $d); }
php > $multi = $memcached->getMulti($data);
php > echo is_array($multi);
1
php > echo count($multi);
100000

I tried to bump it up to a million, but I hit my configured PHP memory limit and promptly decided that if doing a getMulti of one hundred thousand items isn't good enough, you're probably abusing memcached.

like image 130
Charles Avatar answered Oct 02 '22 12:10

Charles


There's no hard limit, but there will be different practical limits that will likely end up being application specific.

like image 26
Dustin Avatar answered Oct 02 '22 14:10

Dustin