memcache and php server optimization
Steven Grimm
sgrimm at facebook.com
Fri Jan 12 14:58:48 UTC 2007
Memcached already supports batched "get" requests. Look for a function
called "get_multi" or similar in your client.
As for batching "set" and "delete" requests, what *is* supported by the
server (though not by all clients) is for the client to send a bunch of
requests without waiting for a response from each one before sending the
next, i.e., sending the commands asynchronously then gathering up all
the responses at the end. The "libmemcache" C client, for example,
supports that. As noted in another thread yesterday, handling rapidfire
asynchronous writes is not *quite* as optimized as it could be on the
server side, but it does work fine, and unless you're doing truly
massive numbers of sets you're unlikely to ever notice the difference.
-Steve
Roberto Spadim wrote:
> i'm new to memcache, but i see some usefull thinks that could be
> implemented
> see my php code:
> <?php
> $memcache= new Memcache;
> $memcache->connect('172.16.0.1',11211); // only one server
> $st=microtime(1);
> $memcache->get('value');
> echo (microtime(1)-$st)."\n"; // ~0.0013 seconds (maybe 1 packet
> to and 1 packet from memcache)
> $st=microtime(1);
> $memcache->get(array('value','value2')); echo
> (microtime(1)-$st)."\n"; // ~0.0026 seconds (maybe 2 packets to and
> 2 packets from memcache)
> ?>
> only if we are sending two packets (i don't know memcache protocol):
> i think that sending only one packet with get two keys could be
> faster than two packets (i don't know if memcache server implements it)
>
> now for set, add and replace:
> $memcache->set( array($key1,$key2,$key3),'1'); // set all keys to 1
> (can make with only one packet?)
> $memcache->set(
> array($key1,$key2,$key3),array($value1,$value2,$value3)); // set
> each key for each value (i don't know if we could use only one packet,
> values can be very big... but keys don't!)
>
> now for delete, allow arrays like:
> $memcache->delete( array($key1,$key2,$key3)); // could be done
> with only one packet too
> today only this work:
> $memcache->delete($key1);
> $memcache->delete($key2);
> $memcache->delete($key3);
>
> now some feature requests, these functions should be only for one
> server!:
> $memcache->getkeyscount($host,$port); // return keys count
> $memcache->getallkeys($host,$port); // get ALL keys
> $memcache->getallkeys($host,$port,0,15); // get keys from 0 to 15,
> // i don't know if we have an index of variables but getallkeys
> with parameters could work with for:
> for ($i=0;$i<$memcache->getkeyscount();$i++){
> $memcache->getallkeys($i*15,15);
> }
>
> i don't know memcache protocol very well but seeing time for
> one(0.0013) and two gets(0.0026) i think that we are sending many(2)
> packets, sending only one packet could be an optimization when we are
> connected with one server, many servers could allow too, but i don't
> know if cpu utilization or network utilization could be too high on
> each memcache server
> thankx guys,
> Roberto Spadim
More information about the memcached
mailing list