Are you really using PHP4? Not related just shocked.
Did you make all these changes at once?
--
Brian.
Well, I don't use the consistent hashing. I guess I am naive. I also
have not heard of this problem before however.
--
Brian.
The 2.2.x branch had the same performance improvement but it wasn't
released until a few minutes ago :) Try the 2.2.5 release, should give
you better performance when using the consistent hashing strategy.
Available at
http://pecl.php.net/package/memcache
//Mikael
I believe the consistent hashing implementation in pecl/memcache is
simply a C port of the original one from Set-ConsistentHash, available from
http://search.cpan.org/~bradfitz/Set-ConsistentHash/
What algorithms are others using? From what I can pick up from the
libmemcached sources it works much the same but without the precomputed
1024 element array. The 100 (or 160 in the case of ketama) points per
server is still computed and sorted, so consistent hashing will always
be slower than the simple modulo operation of the standard algorithm.
It does however make sense to skip the precomputed array and instead
search the continuum for a matching server on each request. One would
have to make more than 1024 requests for the array to pay off, something
the average webpage rendering is unlikely to reach.
//Mikael
The server selection isn't done in an external library, it's just that
the algorithm used is the same as the one in Set-ConsistentHash, though
it uses crc32 or fnv1a instead of sha1 (versus md5 for ketama).
The big difference is that pecl/memcache and Set-ConsistentHash after
having built and sorted the continuum precomputes an array of 1024
buckets, which can then be used by hashing the key and using a modulo
operation on the array. It's computing this array that takes most of the
time. What can be done is, as you say, caching it in shared memory
alongside the persistent connection sockets. I'll have a look at this.
Consistent hashing takes O(log n*w*m) to find a server, not counting the
hash function itself, where n is the number of servers, w is the average
weight of a server (usually 1) and m is number of points per server
(usually 100 or 160). Standard modulo hashing is O(1), so it's
inherently faster.
//Mikael
> <http://search.cpan.org/%7Ebradfitz/Set-ConsistentHash/>
>
> What algorithms are others using? From what I can pick up from the
> libmemcached sources it works much the same but without the
> precomputed 1024 element array. The 100 (or 160 in the case of
> ketama) points per server is still computed and sorted, so
> consistent hashing will always be slower than the simple modulo
> operation of the standard algorithm.
>
> It does however make sense to skip the precomputed array and instead
> search the continuum for a matching server on each request. One
> would have to make more than 1024 requests for the array to pay off,
> something the average webpage rendering is unlikely to reach.
>
> //Mikael
>
>
> Xaxo wrote:
>
>
>
> On Feb 27, 6:48 pm, Mikael Johansson <mik...@synd.info
That what I would have thought, but I'm guessing from what has been said that in this case, a new php process is being started for each request, which means you need to initialize the client once for each request. I'm talking about this quote specifically:
[Pavel Aleksandrov]
> if you calculate several hundred or more hashes each
> time a user opens a page, you get the idea...
Personally, I think the solution would be to set the MaxRequestsPerChild much higher in order to reuse the same php process for many requests, but maybe that's not an option? Or maybe I misunderstood that quote...
Dean.