小天管理 发表于 2024年7月10日 发表于 2024年7月10日 最近使用 golang 写了一个 tls 的测试程序,连接特定服务器接收数据会有 500ms 的延迟,起初以为是网络问题,但是通过 wireshark 抓包查看每次服务端回包都很快,最后发现每次 tls 连接握手成功后,再使用 net.Conn 的 read 接口读取数据时都会有 500ms 延迟。相同的代码,相同运行环境,连接其他服务器时,不会增加延迟。大佬帮忙分析下原因,这 500ms 增加的原因测试环境:win11 22H2go 版本:go version go1.22.5 windows/amd64wireshark 抓包:(可以看到发送数据后,到服务端回包只有 100ms 延迟)打印日志:(可以看到握手成功后,每次读取数据都会有 500ms 延迟,比 100ms 多很多)2024-07-10 16:13:24.2993355 +0800 CST m=+0.027776101 net.Conn start writing2024-07-10 16:13:24.3118851 +0800 CST m=+0.040325701 net.Conn last write 12.6118ms2024-07-10 16:13:24.3119473 +0800 CST m=+0.040387901 net.Conn start reading2024-07-10 16:13:24.3299688 +0800 CST m=+0.058409401 net.Conn last read 18.0215ms2024-07-10 16:13:24.3299688 +0800 CST m=+0.058409401 net.Conn start reading2024-07-10 16:13:24.3305847 +0800 CST m=+0.059025301 net.Conn last read 615.9µs2024-07-10 16:13:24.3307758 +0800 CST m=+0.059216401 net.Conn start writing2024-07-10 16:13:24.3307758 +0800 CST m=+0.059216401 net.Conn last write 0sTLS handshake complete2024-07-10 16:13:24.3313401 +0800 CST m=+0.059780701 net.Conn start writing2024-07-10 16:13:24.3313401 +0800 CST m=+0.059780701 net.Conn last write 0s2024-07-10 16:13:24.3313401 +0800 CST m=+0.059780701 net.Conn start reading2024-07-10 16:13:24.8493165 +0800 CST m=+0.577757101 net.Conn last read 517.9764ms2024-07-10 16:13:24.850016 +0800 CST m=+0.578456601 net.Conn start writing2024-07-10 16:13:24.8505629 +0800 CST m=+0.579003501 net.Conn last write 546.9µs2024-07-10 16:13:24.8510947 +0800 CST m=+0.579535301 net.Conn start reading2024-07-10 16:13:25.3798195 +0800 CST m=+1.108260101 net.Conn last read 528.7248ms2024-07-10 16:13:25.3798195 +0800 CST m=+1.108260101 net.Conn start writing2024-07-10 16:13:25.3804916 +0800 CST m=+1.108932201 net.Conn last write 672.1µs2024-07-10 16:13:25.3811492 +0800 CST m=+1.109589801 net.Conn start reading2024-07-10 16:13:25.9070306 +0800 CST m=+1.635471201 net.Conn last read 525.8814ms2024-07-10 16:13:25.90721 +0800 CST m=+1.635650601 net.Conn start writing2024-07-10 16:13:25.9077158 +0800 CST m=+1.636156401 net.Conn last write 505.8µs代码 demo:https://gist.github.com/kratos1918/6884f248e20130af93a8adf5d2716851
已推荐帖子