Zero-copy in Go: sendfile, splice, and the cost of io.Copy
segflow.github.io原文 ↗
Segflow 用 Go 1.22.12、Linux 6.6 和 512MiB 文件实验说明 `io.Copy` 何时走 sendfile/splice fast path。把 `*os.File` 直接传给 TCPConn 时,strace 看到约 2,958 次 sendfile;包一层普通 `io.Reader` 后,变成约 131k 次 read/write,syscall 时间约 24 倍。文章最实用的规则是:不要随手包 reader/writer,若必须包就保留 `WriterTo`/`ReaderFrom` 等可选接口。
–浏览
评论 · Comments