Go race detector


线上程序发现处理速度变慢,内存占用变大,后面排查发现 build的时候指定了-race 参数,导致处理速度和内存变大。


The cost of race detection varies by program, but for a typical program, memory usage may increase by 5-10x and execution time by 2-20x.

The race detector currently allocates an extra 8 bytes per defer and recover statement. Those extra allocations are not recovered until the goroutine exits. This means that if you have a long-running goroutine that is periodically issuing defer and recover calls, the program memory usage may grow without bound. These memory allocations will not show up in the output of runtime.ReadMemStats or runtime/pprof.


Golang: Concurrency is Hard; So What Can We Do About It?
SRE: Debugging: Simple Memory Leaks in Go
Does the Go race detector catch all data race bugs?
Race-free doesn’t mean deterministic