Re: Performance: Unix sockets vs. TCP/IP sockets

From: Doug McNaught <doug(at)wireboard(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Performance: Unix sockets vs. TCP/IP sockets
Date: 2001-01-26 17:04:27
Message-ID: m3ofwuutwk.fsf@belphigor.mcnaught.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Frank Joerdens <frank(at)joerdens(dot)de> writes:

> On Thu, Jan 25, 2001 at 11:07:19PM -0500, Tom Lane wrote:
> > Frank Joerdens <frank(at)joerdens(dot)de> writes:
> > > What performance penalty can I expect when going over TCP/IP sockets
> > > instead of Unix sockets?
> >
> > On a properly designed kernel, there shouldn't be any measurable
> > performance difference between a local TCP connection and a Unix-socket
> > connection.
>
> Ah. That's good hear. I'd heard that TCP/IP was _significantly_ slower
> than Unix sockets. But maybe that was just Linux.

Much as I hesitate to contradict Tom here, I think I need to qualify
his statement.

For a localhost TCP socket, a write() has to be sent down the network
stack and (possibly) split into packets, which are then sent through
the routing engine and back up through the stack, flow-controlled,
reassembled, and submitted to the receiving socket. Also, ACK packets
have to be sent back to the sender through the same tortuous path.

For a Unix socket, the write() is merely copied into the socket
buffer, and the reader notified that data is ready. Flow control
consists of simply blocking the writer if the buffer is full.

For bulk data, a Unix socket will almost certainly be faster due to
the reduced overhead.

For a Postgres connection, query compilation (if needed) and lookup
time, plus disk i/o if necessary, will dominate. and you shouldn't see
a significant difference between the two types of socket.

-Doug

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mikheev, Vadim 2001-01-26 17:12:09 RE: vacuum
Previous Message Adrian Phillips 2001-01-26 16:58:56 Re: Performance: Unix sockets vs. TCP/IP sockets