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’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 127.0.0.1?

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

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
Aha, cool cool — so, all other things being equal, you wouldn’t expect a socket to be slower than listening on 127.0.0.1? –  Paul D. Waite Dec 9 '11 at 16:41
    
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
1  
Most of the times I tested that the difference was not significant. Pretty sad. –  coredump May 30 '12 at 10:58
add comment

If you are accessing memecached only locally, it IS recommended to listen only to the local IP address 127.0.0.1 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.

share|improve this answer
    
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
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.