Discover Centmin Mod today
Register Now

PHP-FPM Switch from TCP to UNIX domain sockets

Discussion in 'Centmin Mod Insights' started by rdan, Jun 7, 2014.

  1. jeffwidman

    jeffwidman Active Member

    Dec 3, 2014
    Local Time:
    3:27 PM
    I've been looking into this a bunch more for a python server stack I'm working on, and I wanted to clarify for anyone else who starts looking into this.

    From a theoretical perspective, it makes no sense that a properly-configured server will scale out better using TCP. It's actually the opposite. A unix socket has significantly less overhead than a TCP socket and from all the benchmarks I've read, there is a noticeable speed difference. For example, one of the core PostgreSQL devs benchmarked a >30% performance improvement in Unix socket vs TCP socket speed. Redis benchmarks show a ~50% throughput increase for Unix sockets vs TCP sockets.

    If TCP is outperforming unix sockets with high concurrent loads, I suspect it's because something isn't properly configured on the server.... most likely the Linux file descriptor limit (mentioned in the RTCamp article linked to earlier in the thread), although there are other OS-level settings that also affect this. Most centminmod users won't care enough to try to tune OS-level settings, so on a server with the default CentOS linux settings, TCP may scale out better. And you could be hitting limits imposed by the VPS virtualization layer which is out of your control. But on a dedicated box, if the OS is tuned in addition to the webserver/db stack, unix sockets should win hands down.

    That said, TCP vs Unix isn't the bottleneck on 99% centminmod servers. And if it is, most likely the smart business decision is to just get a bigger server rather then spending man-hours trying to tune linux core settings... as most of us can testify, it's easy to fritter away a lot of time in the belly of the beast. ;-)
  2. eva2000

    eva2000 Administrator Staff Member

    May 24, 2014
    Brisbane, Australia
    Local Time:
    9:27 AM
    Nginx 1.25.x
    MariaDB 10.x
    In theory yes, but the context is for PHP-FPM specific TCP vs Unix Sockets and under heavy loads the PHP-FPM Unix sockets aren't as stable as tuned TCP from my own experience and other user reports - this is with file descriptors properly configured too. I know Redis definitely is better with Unix sockets than TCP though

    But yeah maybe partly due to virtualisation limitations i.e OpenVZ and file descriptor limits :)