揭示并解决企业微服务中的Goroutine泄漏:一种动态分析方法
Unveiling and Vanquishing Goroutine Leaks in Enterprise Microservices: A Dynamic Analysis Approach
AI总结:
该研究针对企业Go微服务中消息传递不当引发的goroutine泄漏问题,开发了Goleak与LeakProf两款动态分析工具,在工业场景部署后有效检测修复大量泄漏,显著提升了生产服务性能。
摘要:
Go是一种现代编程语言,在企业微服务系统中日益流行。并发是Go的一等公民,轻量级的“goroutine(Go协程)”是并发执行的构建块。Go倡导通过消息传递在goroutine之间进行通信和同步。Go中消息传递的不当使用会导致“部分死锁”,这是一种隐蔽的并发缺陷:被阻塞的发送方(接收方)始终找不到对应的接收方(发送方),导致被阻塞的goroutine通过其调用栈以及栈上可访问的对象造成内存泄漏。\n 本文针对优步承载了2500多个微服务、规模达7500万行代码的Go单仓代码库,系统研究了消息传递的普遍情况以及由此产生的部分死锁问题。我们开发了两款轻量级动态分析工具:Goleak和LeakProf,用于识别部分死锁。Goleak在单元测试期间检测部分死锁,防止新缺陷被引入。与之对应,LeakProf利用从生产环境部署的服务中获取的goroutine性能剖析数据,定位由复杂控制流、未被探索的执行交错或测试覆盖缺失导致的复杂缺陷。我们分享了在大型工业场景的开发者工作流中部署这些工具的经验与洞见。借助Goleak,我们在遗留代码中发现了857个已存在的goroutine泄漏,并在一年时间内阻止了约260个新泄漏的引入。借助LeakProf,我们发现了24个goroutine泄漏并修复了其中21个,这使得我们部分生产服务的运行速度最高提升了34%,内存占用最高降低了9.2倍。
英文摘要:
Go is a modern programming language gaining popularity in enterprise microservice systems. Concurrency is a first-class citizen in Go with lightweight ``goroutines'' as the building blocks of concurrent execution. Go advocates message-passing to communicate and synchronize among goroutines. Improper use of message passing in Go can result in ``partial deadlocks'' , a subtle concurrency bug where a blocked sender (receiver) never finds a corresponding receiver (sender), causing the blocked goroutine to leak memory, via its call stack and objects reachable from the stack. In this paper, we systematically study the prevalence of message passing and the resulting partial deadlocks in 75 million lines of Uber's Go monorepo hosting over 2500 microservices. We develop two lightweight, dynamic analysis tools: Goleak and LeakProf, designed to identify partial deadlocks. Goleak detects partial deadlocks during unit testing and prevents the introduction of new bugs. Conversely, LeakProf uses goroutine profiles obtained from services deployed in production to pinpoint intricate bugs arising from complex control flow, unexplored interleavings, or the absence of test coverage. We share our experience and insights deploying these tools in developer workflows in a large industrial setting. Using Goleak we unearthed 857 pre-existing goroutine leaks in the legacy code and prevented the introduction of around 260 new leaks over one year period. Using LeakProf we found 24 and fixed 21 goroutine leaks, which resulted in up to 34% speedup and 9.2x memory reduction in some of our production services.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。