由于 AF_INET 中涉及三向握手,AF_INET 是否比 AF_UNIX 慢?
Is AF_INET slower than AF_UNIX due to three way hand-shake involved in AF_INET?
我有一个要求,其中服务器需要与 2 个客户端交互,一个驻留在本地计算机上,一个驻留在远程计算机上。
所以,最初我想创建一个套接字,使用 AF_UNIX 与本地客户端通信(因为它比 AF_INET 快),而 AF_INET 用于与远程通信, 并在它们之间轮询。
但是对于本地客户端,通道只会在开始时创建,它将永久存在直到服务器运行,即单个接受,然后是多个read/writes。
那么,我可以用 AF_INET 替换这个 AF_UNIX 吗,因为连接建立只会进行一次?
在 AF_INET 的情况下,性能在哪里受到影响?是三向握手还是其他地方?
引自Performance: TCP loopback connection vs Unix Domain Socket:
When the server and client benchmark programs run on the same box, both the TCP/IP loopback and unix domain sockets can be used. Depending on the platform, unix domain sockets can achieve around 50% more throughput than the TCP/IP loopback (on Linux for instance). The default behavior of redis-benchmark is to use the TCP/IP loopback.
但是,确保性能提升值得权衡使应用程序的网络堆栈复杂化(通过根据客户端位置使用各种类型的套接字)。
我有一个要求,其中服务器需要与 2 个客户端交互,一个驻留在本地计算机上,一个驻留在远程计算机上。
所以,最初我想创建一个套接字,使用 AF_UNIX 与本地客户端通信(因为它比 AF_INET 快),而 AF_INET 用于与远程通信, 并在它们之间轮询。
但是对于本地客户端,通道只会在开始时创建,它将永久存在直到服务器运行,即单个接受,然后是多个read/writes。
那么,我可以用 AF_INET 替换这个 AF_UNIX 吗,因为连接建立只会进行一次? 在 AF_INET 的情况下,性能在哪里受到影响?是三向握手还是其他地方?
引自Performance: TCP loopback connection vs Unix Domain Socket:
When the server and client benchmark programs run on the same box, both the TCP/IP loopback and unix domain sockets can be used. Depending on the platform, unix domain sockets can achieve around 50% more throughput than the TCP/IP loopback (on Linux for instance). The default behavior of redis-benchmark is to use the TCP/IP loopback.
但是,确保性能提升值得权衡使应用程序的网络堆栈复杂化(通过根据客户端位置使用各种类型的套接字)。