views:

435

answers:

2

I was setting up Django on Cherokee today (using SCGI), and I noticed that the Django docs say that you can use either a host/port combination or a socket for communication between the webserver and Django.

The only thing they have to say on the matter is

What you choose is a manner of preference; a TCP socket is usually easier due to permissions issues.

(Incidentally, I've had permissions problems with doing this with a socket, but not with a host :). )

I vaguely remember how sockets work from my systems programming class, but I'm really curious as to what the effective difference is between the two. Any time there's a choice of something, there's someone with an opinion on the matter, so I was hoping to get that. In particular, is there any performance difference?

Or, if it really doesn't matter at all, I'd just like some confirmation, so I can continue on with my programming and ignore this sysadmin-y stuff.

+4  A: 

A UNIX socket is administered as a file in the file system. You need to set user/group values and permissions correctly. It also has to be in any jailroot you are using (a common error when using postfix + mysql).

You do not need to do that for a TCP socket, as long as you bind to a port > 1000.

A UNIX socket can be considered slightly faster as it does not have a network protocol and thus skips the network stack, but is limited to a single machine. TCP on the other hands lets you connect to services running on different hosts.

ebo
port > 1023 actually
Thomas
+1  A: 

The real difference I think is that if you have a really high connection rate with short-lived connections you can run out of ports because used ports end up in TIME_WAIT state for a while with TCP. Not so with named sockets.

I'd use a named socket for local connections if I know that it will only be used by the local host. But for this use.... yeah it won't really matter. Not performance wise or otherwise. It's easy to change later if you change your mind. Just make sure to firewall the TCP port if you use that option.

And again, a TCP socket is also a socket.

Thomas
Helpful, thank you!
Xiong Chiamiov