When benchmarking regular PHP 5.6 through unix socket the results are many order of magnitues better than tcp port.
When I run a command like this:
$ ab -k -n 10000 -c 1000 http://127.0.0.1/api/user/1
I get an avg 3272 reqs per second.
But with tcp port instead of unix socket I get 6.5 reqs per second.
With wrk
$ wrk -t1 -c1000 -d5s http://127.0.0.1:80/api/user/1
on unix socket: 6500 req per second
on tcp port: 300 req per second
How am I supposed to use these benchmarks to get a feel of how my server and code can handle load when I get these kinds of results?
Should I trust the tcp port or unix socket one?
You can trust the ab and wrk numbers.
You should therefore use Unix Sockets on production:
Unix Domain Sockets make nginx faster to communicate with php-fpm, and use less resource, because TCP has an overhead, as protocol, over Unix sockets, even on the loopback. Your numbers show it.
Unix Domain Sockets are not routable, so they are not accessible from the outside, so they are usually considered safer than TCP for local communication. Disabling the firewall may allow external process to access directly php-fpm, whereas with Unix sockets this is never possible, but they are local by definition.
Of course, the main bottleneck will be the communication between the clients and nginx, using HTTP/TCP, but at least you can be confident that everything is as good as possible within your server, by using Unix sockets for php-fpm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With