SetWriteDeadline有什么用

What are the uses of SetWriteDeadline

谁能给我一些我可能会使用的场景 SetWriteDeadline? I know that SetReadDeadline 帮助开发人员确定连接的端点是否仍然可以访问(在 PING/PONG 帧的帮助下),但是我不明白为什么我可能会使用 SetWriteDeadline。

Write to a connection returns an error when the write operation does not complete by the last set deadline.

写入截止日期的典型用途是检测未读取数据或未以可接受的速率读取数据的对等方。

健壮的应用程序会同时设置读取和写入截止时间(但通常不会设置为相同的值)。

A robust application will set both read and write deadlines

但最好使用 Go 1.12(2019 年第一季度)。
请参见 golang/go issue 25729net: SetDeadline 性能不佳

最近已修复:

Both the improvements in throughput and latency are far less affected by -cpu values. Nice job!