FastCGI on port vs. on socket

Xiong Chiamiov picture Xiong Chiamiov · Jul 29, 2009 · Viewed 12.5k times · Source

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.

Answer

ebo picture ebo · Jul 29, 2009

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.