Why does GC stat minor_gc_count decrement?

我们两清 提交于 2020-02-23 10:16:08

问题


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}

回答1:


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

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.

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

Process.pid

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.

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.



来源:https://stackoverflow.com/questions/59198840/why-does-gc-stat-minor-gc-count-decrement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!