-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Milestone
Description
sendfile
only allows the source to be a mmap
-able file descriptor. Using splice
in the implementation of (net.Conn).ReadFrom
allows net.Conn
to get the same sort of performance benefits as *os.File
when io.Copy
is used. (In theory, the src can be any fd.)
Pros:
- Uses the fastest (AFAIK) socket -> socket method available on Linux. (Fundamentally, this is how haproxy works.)
- Can be non-blocking (in the sense that both sockets are talking to the netpoller.)
- Transparent perf improvements to existing users of
io.Copy
.
Cons:
- Increased implementation complexity: requires two calls to
splice
, and a call topipe
, along with associatedpd.WaitRead()
/pd.WaitWrite()
business. - Architecture-specific.
For people writing proxies in Go, this kind of optimization could be huge.
If this sounds agreeable, I can send in a patch next week.
valyala, pwaller, bg5sbk, llpamies, thatguystone and 19 more