简体   繁体   English

在Golang 1.4.1中由GC引起的cpu核心是什么

[英]What is the cpu cores caused by GC in Golang 1.4.1

I have recently come across a situation where one of our Golang app, consuming almost 30GB memory, will periodically eating all 24 cpu cores with nearly almost 100%. 我最近遇到过这样一种情况:我们的Golang应用程序消耗了近30GB的内存,会定期吃掉所有24个CPU内核几乎100%。 This will last maybe for more than 3 seconds. 这将持续超过3秒。 Our Golang version is 1.4.1 on linux 64-bit. 我们的Golang版本在Linux 64位上是1.4.1。

I have googled for some info. 我已经google了一些信息。 Here is my assumption: 这是我的假设:

  • in our app, we use a data type []map[string]*list and the instance of this type will contain more than 250K keys. 在我们的应用程序中,我们使用数据类型[]map[string]*list ,此类型的实例将包含超过250K的键。
  • maybe the gc in golang 1.4.1 consuming more cpu time and stop the world. 也许golang 1.4.1中的gc消耗更多的CPU时间并阻止世界。 However, i can not find the parameter to configure the parallelism of gc goroutines(threads). 但是,我找不到用于配置gc goroutines(线程)并行性的参数。 And, does it have some relationship with the GOMAXPROCS parameter. 并且,它与GOMAXPROCS参数有一些关系GOMAXPROCS

You've really gotta profile to figure a problem like this out. 你真的得知道这样的问题。

That said you might be able to reduce the load you put on the garbage collector. 这说你可能能够减少你在垃圾收集器上的负担。 Here are a couple of suggestions: 以下是一些建议:

  1. Linked lists result in a lot of small allocations. 链接列表会导致大量小额分配。 Have you considered using a []map[string][]whatever_you_are_storing ? 您是否考虑过使用[]map[string][]whatever_you_are_storing
  2. Are you adding and removing things from this giant map? 你在这个巨大的地图上添加和删除东西吗? Are the things you're adding and removing all basically the same? 您添加和删除的内容基本相同吗? If so you may be able to use a sync.Pool . 如果是这样,您可以使用sync.Pool
  3. Have you tried storing the item directly: map[string]list instead of map[string]*list . 您是否尝试过直接存储项目: map[string]list而不是map[string]*list It will change the behavior of your program, but for a small struct it may make sense anyway. 它会改变你的程序的行为,但对于一个小的结构,它可能是有意义的。

Those are shots in the dark. 那些是黑暗中的镜头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM