golang - goroutine leak
为情所困
为情所困 2017-04-26 09:01:29
0
0
766

描述

需求是开发一个golang binary周期性收集host上docker container的log信息。结果运行的时候使用go pprof查看发现goroutine泄露了。自己试了半天没有解决。

详情

  • 内存使用情况,内存会不断增加,一直到33m:

    CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS goleak 0.00% 11.25 MiB / 32 MiB 35.14% 0 B / 0 B 6.112 MB / 0 B 0
  • pprof中结果:

    /debug/pprof/ profiles: 0 block 63 goroutine 0 heap 7 threadcreate full goroutine stack dump

    由于debug期间个人对代码进行了优化,是个goroutine增加速度大大降低。最多的时候有3000个。

GitHub repo

goroutine-leak,使用govendor管理依赖包。
我把有问题的代码抽离出来放到main.go里,并且维护在了github上,地址goroutine-leak。里面默认集成了pprof功能,感兴趣的小伙伴可以一起debug学习下。

我也会不断尝试各种方法来解决这个问题。

为情所困
为情所困

Antworte allen (0)
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!