Golang High‑Performance Practice: Architecture and Optimization Techniques
This article presents a comprehensive technical sharing on Golang high‑performance engineering, covering architecture design, profiling tools, concurrency optimizations, distributed rate limiting, timer mechanisms, GC tuning, and deployment strategies, supplemented with PPT links and extensive code excerpts for practical reference.
The author recounts a long‑planned internal technical sharing on Golang high‑performance practice, aimed at developers who have moved from entry‑level to advanced usage, focusing on architectural and framework design rather than language basics.
Presentation materials are hosted on GitHub, Slideshare, and a direct PDF download, with URLs provided for easy access and encouragement to star and follow the repository.
The extracted PPT content outlines a CDN refresh system project and enumerates numerous optimization topics, including segment‑locked maps, sequential queues, time wheels, RPC design, distributed rate limiting, leader election, reactor architecture, profiling with pprof, perf, strace, tcpdump, and various performance‑critical patterns such as fast/slow queues, busy polling, timer implementations, and GC tuning.
# xiaorui.cc 1. github.com/rfyiamcool xiaorui.cc Golang 高高性能实战 2. CDN 刷新系统 是一个高性能、可扩 展的分布式系统. 支持全网刷新及预缓存业务. 3. 架构及框架 目目录 Contents 1 调优2 深度排雷雷3 上线部署4 总结5 4. 架构及框架设计1 5. 架构设计 EngingSrv SLBClient EngingSrv Proxy Proxy Proxy HA http rpc 6. 框架设计 Poller Pusher Notify Saver TimerRester RingBuffer Chan Chan Chan Chan disPatcher DelayCtl EventBus ChanChan 7. 框架设计 • 模块之间解耦 • 复⽤用性强 • ⽅方便便监控 • 分布式扩展 • 读写⾼高的场景 • 使用ringbuffer避免chan的锁消耗 • EventBus • 控制功能worker池的start / stop 8. 技术选型 语⾔言: Golang 框架: Gin 压缩: Snappy 序列列化: Json-iterator ORM: Gorm 客户端: imroc/req ⽇日志: Logrus 配置: Toml 缓存: Redis 持久化: Mysql 9. 设计调优2 10. 基本优化 提前预估size, make 之 临时的map, slice,可使用sync.pool 大于32kb,也可使用 sync.pool 11. 基本优化 不要滥用time.After,多用事件通知 不要滥用goroutine, 减少gc压力 不要滥用锁, 引起runtime上下文切换 使用unsafe装换类型 不要总是[]byte、String转换. 12. 基本优化 减少使用reflect反射使用 减少不必要的defer调用 使用atomic实现无锁逻辑 13. 业务调优 减少网络io的消耗 批量接口 缩减网络调用链 使用连接池 缓存内存化 减少同步逻辑 使用压缩, 节省带宽 14. 通信协议更换 HTTP vs RPC 15. 全局任务状态 Map Syncer Rwlock Map Rwlock Caller CRC32 &mod ... ... (remaining lines omitted for brevity) ... 55. wrk -t8 -c800 -d100s -T10s --script=js --latency http://xxxxx:9181/v1/engine/task 56. 上线部署4 57. 打包方法 Engine端 • build • pack • repo • salt • unpack • reload Proxy端, 封装RPM包上线 . go build -ldflags "-X main.Version=V0.1.10" main.go 58. EngingSrv SLBMGR EngingSrv Proxy 灰度平滑迁移-SLB层 • 通过SLB删除主机 • Engine不接受新任务 • Engine正常处理回报 • client需要有重试机制 权重及删除主机的区别 http rpc 59. 灰度平滑迁移-框架层 ChannelPoller Pusher push Push Pull # 伪代码 recvAndSetExit(signal) publishSigWorerks() if globalExited && len(queue) == 0 && pushExit { return } wait(saveQueueExit) wait(eventBus) • 从调用链最前端开始顺序关闭. • 持久化的数据要优先保证 • join住所有的业务协程. 60. 收集分布式日志 Producter • 追踪所有调用链 • 计算耗时 • 排查问题 Kafka tcp/udp inotify Rsyslog Producter File ElasticSearch consumer 61. 如何报警通知 ChannelPoller Pusher push Push Pull AlertMan 服务本身主动去上报异常 ! 异步去上报 ! 异常抽样报警 ! 62. 状态监控页面 63. 总结5 64. 性能演进 1w 1.5w 2w 3w + QPS 65. GC 还需优化 66. 协程太多 67. Q & A
The sharing concludes with a summary of performance evolution over weeks, highlights remaining challenges such as GC overhead and excessive goroutine counts, and invites further discussion through a Q&A section.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.