memcache and php server optimization

Roberto Spadim roberto at spadim.com.br
Fri Jan 12 13:07:17 UTC 2007


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