Two hashing methods are supported: CRC32 FNV
The configuration is as follows:
; Hash function {CRC32, FNV}
memcache.hash_function= FNV
Set Key script:
<?php$cluster = array (Array (' Host ' => ' 127.0.0.1 ', ' Port ' => ' 11211 '), Array (' Host ' => ' 127.0.0.1 ', ' Port ' => ' 11212 '), Array (' Host ' => ' 127.0.0.1 ', ' Port ' => ' 11213 '), Array (' Host ' => ' 127.0.0.1 ', ' Port ' => ' 11214 '), Array (' Host ' => ' 127.0.0.1 ', ' Port ' => ' 11215 '),); $ memcache = new memcache;foreach ($cluster as $mc) {$host = $MC [' Host ']; $port = $MC [' Port '];if ($memcache->addserver ($host, $port)) {echo "Add $host: $port to cluster\n ";} else {echo "failed to add $host: $port to cluster\n";}} $ok = 0;for ($n =1; $n <= 200000 ; $n +) { $key = "K". $n;if (! $memcache->set ($key, 1)) {echo FAILED&NBSP;TO&NBSP;SET&NBSP; $key \ n ";} else {$ok ++;} if ($n % 100 == 0) {echo "completed set $n key to Cache\n ";}} echo "set ok: $ok \ n"; $memcache->close ();? >
To start the cache script:
#!/bin/bashpkill memcachedif [$? = 0];thenecho "Kill all Memcached" Elseecho "failed to kill cached" Exit 1fimemcached-d -P 11211-u memcached-m 64-c 1024x768 &memcached-d-P 11212-u memcached-m 64-c 1024x768 &memcached-d-P 11213-u m Emcached-m 64-c 1024x768 &memcached-d-P 11214-u memcached-m 64-c 1024x768 &memcached-d-P 11215-u memcached-m 64 -C 1024x768 &sleep 1ps aux | grep memcached
Result Check script:
#!/bin/basht11211= ' echo Stats | NC 127.0.0.1 11211 | grep Cmd_set | awk ' {print $} ' t11212= ' echo stats | NC 127.0.0.1 11212 | grep Cmd_set | awk ' {print $} ' t11213= ' echo stats | NC 127.0.0.1 11213 | grep Cmd_set | awk ' {print $} ' t11214= ' echo stats | NC 127.0.0.1 11214 | grep Cmd_set | awk ' {print $} ' t11215= ' echo stats | NC 127.0.0.1 11215 | grep Cmd_set | awk ' {print $} ' echo ' 11211 = $T 11211 "echo" 11212 = $T 11212 "echo" 11213 = $T 11213 "echo" 11214 = $T 11214 "echo" 11215 = $T 1 1215 "
Final result comparison:
CRC32:
11211 = 51180
11212 = 47519
11213 = 26179
11214 = 29082
11215 = 46040
Fnv
11211 = 47085
11212 = 35358
11213 = 49721
11214 = 18787
11215 = 49049
PHP memcache Hash Method equalization Test