惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
B
Blog
The Register - Security
The Register - Security
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
F
Full Disclosure
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
美团技术团队
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
D
DataBreaches.Net
Martin Fowler
Martin Fowler
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
The Cloudflare Blog
博客园 - 【当耐特】
U
Unit 42
月光博客
月光博客
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
博客园 - 聂微东
I
InfoQ
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
Cyberwarzone
Cyberwarzone
V
V2EX
S
Securelist
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Heimdal Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tor Project blog

博客园 - 雨V幕

使用chromedp 来做人工模拟操作爬取数据方法 遍历redis按照前缀给未设置过期时间的数据添加过期时间 使用rabbitmq 进行任务调度 使用vscode 调试 Python 使用power shell 拆分 csv文件 将大文件拆分成小文件。 使用postman 添加预处理验签。 go 使用pprof 进行问题排查 Mysql无主键删除重复数据的快速方法 解决mysql 事务死锁的方法 go在处理批量下载时候出现fatal error: runtime: out of memory AnalyticDB 创建db go 序列化反序列化之后时区信息丢失 clickhouse 进行建表期间的一些优化 kraots2.0 在windows 环境搭建开发环境 Sql Server使用函数获取拼音码 关于async 和await关键字 使用kubespray 一键部署 containerd 的安装和熟悉 VMware 配置双网卡实现上网和固定ip
使用trace进行排查网络瓶颈
雨V幕 · 2025-09-25 · via 博客园 - 雨V幕
func NewHTTPTraceLogger(ctx context.Context, fileUrl string, fragmentID, attempt int) context.Context {
	traceStart := time.Now()
	var dnsStart, connectStart, tlsStart, gotConnTime time.Time

	trace := &httptrace.ClientTrace{
		DNSStart: func(info httptrace.DNSStartInfo) {
			dnsStart = time.Now()
		},
		DNSDone: func(info httptrace.DNSDoneInfo) {
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d DNSDone: %+v cost=%v",
				fileUrl, fragmentID, attempt, info, time.Since(dnsStart))
		},
		ConnectStart: func(network, addr string) {
			connectStart = time.Now()
		},
		ConnectDone: func(network, addr string, err error) {
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d ConnectDone: %s %s err=%v cost=%v",
				fileUrl, fragmentID, attempt, network, addr, err, time.Since(connectStart))
		},
		TLSHandshakeStart: func() {
			tlsStart = time.Now()
		},
		TLSHandshakeDone: func(cs tls.ConnectionState, err error) {
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d TLSHandshakeDone err=%v cost=%v",
				fileUrl, fragmentID, attempt, err, time.Since(tlsStart))
		},
		GotConn: func(connInfo httptrace.GotConnInfo) {
			gotConnTime = time.Now()
			total := time.Since(traceStart)
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d GotConn reused=%v idleTime=%v total=%v",
				fileUrl, fragmentID, attempt, connInfo.Reused, connInfo.IdleTime, total)
		},
		GotFirstResponseByte: func() {
			ttfb := time.Since(gotConnTime)
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d GotFirstResponseByte TTFB=%v",
				fileUrl, fragmentID, attempt, ttfb)
		},
	}

	return httptrace.WithClientTrace(ctx, trace)
}

  使用:

func NewHTTPTraceLogger(ctx context.Context, fileUrl string, fragmentID, attempt int) context.Context {
	traceStart := time.Now()
	var dnsStart, connectStart, tlsStart, gotConnTime time.Time

	trace := &httptrace.ClientTrace{
		DNSStart: func(info httptrace.DNSStartInfo) {
			dnsStart = time.Now()
		},
		DNSDone: func(info httptrace.DNSDoneInfo) {
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d DNSDone: %+v cost=%v",
				fileUrl, fragmentID, attempt, info, time.Since(dnsStart))
		},
		ConnectStart: func(network, addr string) {
			connectStart = time.Now()
		},
		ConnectDone: func(network, addr string, err error) {
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d ConnectDone: %s %s err=%v cost=%v",
				fileUrl, fragmentID, attempt, network, addr, err, time.Since(connectStart))
		},
		TLSHandshakeStart: func() {
			tlsStart = time.Now()
		},
		TLSHandshakeDone: func(cs tls.ConnectionState, err error) {
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d TLSHandshakeDone err=%v cost=%v",
				fileUrl, fragmentID, attempt, err, time.Since(tlsStart))
		},
		GotConn: func(connInfo httptrace.GotConnInfo) {
			gotConnTime = time.Now()
			total := time.Since(traceStart)
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d GotConn reused=%v idleTime=%v total=%v",
				fileUrl, fragmentID, attempt, connInfo.Reused, connInfo.IdleTime, total)
		},
		GotFirstResponseByte: func() {
			ttfb := time.Since(gotConnTime)
			g.Log().Infof(ctx, "[trace] fileUrl=%s fragment=%d attempt=%d GotFirstResponseByte TTFB=%v",
				fileUrl, fragmentID, attempt, ttfb)
		},
	}

	return httptrace.WithClientTrace(ctx, trace)
}