为什么GC stat minor_gc_count递减? [英] Why does GC stat minor_gc_count decrement?

查看:109
本文介绍了为什么GC stat minor_gc_count递减?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个heroku应用.当我早上检查GC.stat时,GC.stat[:minor_gc_count]是51.当天晚些时候是50.

We have an heroku app. When I check GC.stat in the morning, GC.stat[:minor_gc_count] is 51. Later in the day it is 50.

根据我的理解,这应该是垃圾收集器进行次扫描的次数,所以第二天早上去是有道理的,但是为什么会减少呢?

From my understanding, this should be the number of times the garbage collector has done a minor sweep, so going up the next morning would make sense, but why would it decrease?

510 talos-intelligence :>heroku run rails c --remote production
Running rails c on ⬢ talosintelligence... up, run.2287 (Standard-1X)
Loading production environment (Rails 5.2.2.1)
irb(main):001:0> GC.stat
=> {:count=>63, :heap_allocated_pages=>1753, :heap_sorted_length=>1753, :heap_allocatable_pages=>0, :heap_available_slots=>714528, :heap_live_slots=>713742, :heap_free_slots=>786, :heap_final_slots=>0, :heap_marked_slots=>471239, :heap_eden_pages=>1753, :heap_tomb_pages=>0, :total_allocated_pages=>1753, :total_freed_pages=>0, :total_allocated_objects=>2802530, :total_freed_objects=>2088788, :malloc_increase_bytes=>65256, :malloc_increase_bytes_limit=>32225676, :minor_gc_count=>51, :major_gc_count=>12, :remembered_wb_unprotected_objects=>4626, :remembered_wb_unprotected_objects_limit=>8538, :old_objects=>458044, :old_objects_limit=>838856, :oldmalloc_increase_bytes=>65712, :oldmalloc_increase_bytes_limit=>19737900}
irb(main):002:0> exit
**Airbrake: closed
511 talos-intelligence :>heroku run rails c --remote production
Running rails c on ⬢ talosintelligence... up, run.7226 (Standard-1X)
Loading production environment (Rails 5.2.2.1)
irb(main):001:0> GC.stat
=> {:count=>62, :heap_allocated_pages=>1618, :heap_sorted_length=>1913, :heap_allocatable_pages=>295, :heap_available_slots=>659511, :heap_live_slots=>659395, :heap_free_slots=>116, :heap_final_slots=>0, :heap_marked_slots=>467961, :heap_eden_pages=>1618, :heap_tomb_pages=>0, :total_allocated_pages=>1618, :total_freed_pages=>0, :total_allocated_objects=>2726093, :total_freed_objects=>2066698, :malloc_increase_bytes=>5662240, :malloc_increase_bytes_limit=>24780563, :minor_gc_count=>50, :major_gc_count=>12, :remembered_wb_unprotected_objects=>4632, :remembered_wb_unprotected_objects_limit=>9262, :old_objects=>456572, :old_objects_limit=>913146, :oldmalloc_increase_bytes=>7549584, :oldmalloc_increase_bytes_limit=>19737900}

推荐答案

问题可能在测试本身中.当您运行GC.stat时,它将返回有关当前正在运行的进程的信息.没关系问题是每次您运行

Problem might be in the test itself. When you run GC.stat it will return informations about your currently running process. Which is fine. The problem is that every time you run

heroku run rails c --remote production

在您的控制台中,它将不会连接到您当前在Heroku上运行的应用程序的进程.它将为控制台启动一个新进程,您将为该新创建的进程而不是您的应用程序响应Web请求的进程返回GC.stat.这就是为什么它如此之低,甚至可能降低的原因.

in your console, it will not connect to the process of you currently running application on the Heroku. It will launch a new process for the console and you are getting back the GC.stat for this newly created process, not for the process where your application responds to the web requests. This is the reason why it is so low and why it even may decrease.

您实际上可以自己进行测试.当您连接到Heroku上的rails控制台时,请运行以下ruby代码:

You can actually test it on your own. When you connect to the rails console on the Heroku, run following ruby code:

Process.pid

它将返回当前进程的ID.然后断开与Heroku的连接,然后重新连接并再次运行Process.pid.您会看到它将返回不同的进程ID,因为当您断开与控制台的连接并为新连接创建新进程时,它会停止上一个进程.

It will return the ID of the current process. Then disconnect from the Heroku and connect back again and run Process.pid again. You will see that it will return different process ID because it stoped the previous process when you have disconnected from the console and created the new process for the new connection.

您还可以尝试在这些连接中运行GC.stat,您会发现它们可能有所不同,并且这些连接之间的计数可能会上下波动,这是因为进程之间并不相互依赖.

You can also try to run GC.stat in these connections and you will see, that they will be probably different and the counts can go up and down between these connections, that is because the processes are not dependent on each other.

这篇关于为什么GC stat minor_gc_count递减?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆