runtime 中的环境变量
The following environment variables ($name or %name%, depending on the host operating system) control the run-time behavior of Go programs. The meanings and use may change from release to release.
GOGC
The GOGC variable sets the initial garbage collection target percentage. A collection is triggered when the ratio of freshly allocated data to live data remaining after the previous collection reaches this percentage. The default is GOGC=100. Setting GOGC=off disables the garbage collector entirely. The runtime/debug package’s SetGCPercent function allows changing this percentage at run time.
GODEBUG
只要在程序执行之前加上环境变量GODEBUG gctrace =1 ,如: GODEBUG=gctrace=1 ./binary or GODEBUG=gctrace=1 go run main.go or GODEBUG gctrace =1 ./binary > trace.log
程序将会显示gc信息,如下
1 |
|
1 |
|