views:

732

answers:

3

In our current use of memcached, we are running into problems in a high volume server because so much time is used setting up and tearing down connections to our memcache server. Would using persistent connections to memcached help alleviate this problem?

Also, what is the preferred way to connect and use persistent memcahced connections? I was thinking of setting a "pool_size" variable then randomly choosing from 1-$POOL_SIZE and using that connection

$mem = new Memcached(rand(1, $pool_size));

Either I am looking in the wrong place or there is not a lot of information on this out there.

+1  A: 

The php client doesn't handle persistent connections. you either need to use your pooling idea, or use a 3rd party memcached client for php that supports persistent connections.

like this one:

http://github.com/andreiz/php-memcached/tree/master

Byron Whitlock
A: 

I have read that persistent connections feature is broken in the "memcached" PHP extension.

First: the "persistent" connection is not destroyed. (This is ok.)

Second: when you try to reuse it, it creates a new one! (This is bad!)

Result: memory leaks, increasingly consuming all available RAM.

Check here: http://brian.moonspot.net/php-memcached-issues

As I said, I haven't experienced this myself - I just read this information in the linked article.

J. Bruni
A: 

Both pecl/memcache and pecl/memcached support persistent connections per process. However, the bug does exist in pecl/memcached at this time.

Brian Moon