Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a system where there are connections to a memcache server from several different files and servers.

I would like to stay with one server but keep the option of increasing the number of memcache servers (for periods of of high traffic).

My idea is to tell memcache there are two servers, while the two urls will point (by DNS) to a single server. In the future if I want I can add a server and change DNS without changing the code in many places.

Is this a good practice? Is there a performance cost to the fact that there are two server connections but they both point to the same server?

Any other idea how to achive instant expeandability of memcache capacity without need to change the code and deploy ?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It depends on the memcached client you're using and how it determines to hash keys across multiple servers. You should not expect more performance by specifying two servers versus one since a single memcached server will serve more connections than your single web server can handle (most likely). In fact having the client try to hash keys across two different servers (that are actually the same) may do more harm than good.

If you don't want to deploy again, then I would list your servers in an ENVIRONMENT variable pulled in on the server as a configuration option. For instance, ENV['MEMCACHE_SERVERS'] and simply configure it server-side without deploying again.

The beauty with memcache is that it's not meant to be redundant or fail-over, it's not a persistence store. It could even completely go dead and you're site will simply just have a cache-hit of 0% but at least it's still functioning.

See more about redundancy and fail-over on their FAQ.

share|improve this answer
    
Thanks for the answer. However I'm still not sure if its a good practice in my case. I have multiple web servers sharing the memcache so the rationale of it being faster than the web server does not apply. My code does depend on the memcache server availability. It is used to distribute some essential data across servers. Why should I not expect more performance from two servers than with one? The memcache PHP library will do hashing on the keys and distribute if there are multiple servers no? –  Niro Nov 18 '11 at 9:26
    
(haven't logged in for awhile, sorry for the late response) - I wouldn't distribute critical data to memcache and expect it to be there. Memcache is caching, not storage. Use redis or another persistence store. –  databyte Dec 1 '11 at 17:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.