I’m setting up a Django website to use memcached to cache its pages.

(The content of each page won’t change very often at all, so I’m hoping that most of the site will be served from memcached most of the time, and thus be able to handle a lot of traffic reasonably well.)

Both the website and memcached will run on one virtual server, running on Debian Squeeze.

Given that set-up, I thought I might set memcached to listen via a Unix domain socket (see http://code.google.com/p/memcached/wiki/NewConfiguringServer#Unix_Sockets), instead of over a network interface. Although my virtual server is pretty extensively firewalled, as I only need memcached to be to be accessible by a single local user (i.e. the Django site), I figure I might as well keep it restricted.

Are there any drawbacks to having memcached listen over a Unix domain socket, when both memcached and its client are on the same server? E.g. might a Unix domain socket be slower than listening on

(Apologies for such a newbie question — as you can probably tell, I haven’t used memcached before, or done much with Unix/Linux.)


Typically the unix socket versus network port question breaks down like this:

Unix Socket Drawbacks

Can only be accessed localy

Unix Socket Benefits

Eliminates TCP/IP overhead

Network Drawbacks

Security TCP/IP overhead

Network Benefits

Services can be accessed over the network

I use this as a general guide to nearly any service, including memcached, MySQL, and other services.

This is drastically over simplified but is where I start.

  • Aha, cool cool — so, all other things being equal, you wouldn’t expect a socket to be slower than listening on – Paul D. Waite Dec 9 '11 at 16:41
  • 1
    Actaully would "expect" it to be faster due to the lack of TCP/IP overhead but you never know until you test. – jeffatrackaid Dec 9 '11 at 16:49
  • Sure. Excellent — I’ll post back here if I ever look into it properly. – Paul D. Waite Dec 9 '11 at 16:57
  • 2
    Most of the times I tested that the difference was not significant. Pretty sad. – coredump May 30 '12 at 10:58

If you are accessing memecached only locally, it IS recommended to listen only to the local IP address or use unix socket.

This is a good practice even if you have a firewalled and protected environment. Image that you have moved your server out of this network to another untrusted network. So, you have to worry about securing your memcached port.

  • Sure, I figured a more restricted set-up was better if it didn‘t cause any other drawbacks. – Paul D. Waite Dec 9 '11 at 16:41
  • Yes, the more restricted setup is better in terms of security. In your case, there will be no performance difference. – Khaled Dec 9 '11 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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