Ruby的GC.stat的字段是什么意思? [英] What do the fields of Ruby's GC.stat mean?

查看:150
本文介绍了Ruby的GC.stat的字段是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GC.stat 来剖析Rails应用程序中的内存使用情况。 GC.stat 返回一个包含以下键的散列:

 :count 
:heap_used
:heap_length
:heap_increment
:heap_live_num
:heap_free_num
:heap_final_num

有人知道这些值究竟是什么意思吗? Ruby源代码中没有它们的文档( gc.c ),只是一个评论:哈希的内容是实现定义的,将来可能会改变。



这些字段中的某些字段是有意义的上下文,例如 count 是Ruby分配的堆数。但是什么是 heap_final_num ?什么是 heap_increment ?是 heap_length 最小堆大小?



我在摆弄 RUBY_MIN_HEAP_SLOTS RUBY_FREE_MIN RUBY_GC_MALLOC_LIMIT ,但改变这些env vars似乎对:heap_count :heap_length 。如果我从根本上增加最小堆插槽,我希望:heap_count 会下降。所以我真的很想知道所有的 GC.stat 值代表的是什么!



我正在使用Ruby 1.9.3。

解决方案 ,例如gc运行了多少次

:heap_used - 分配堆的数量,ruby默认创建一个堆,如果它不足以分配所有对象,则增加堆号。

:heap_length - 堆的大小。这是第一个堆大小。理想情况下,脚本启动后应该有一堆

:heap_increment - 将添加到最后一个堆大小如果红宝石创建新堆



:heap_live_num - 分配了多少个堆槽



:heap_free_num - 有多少堆空闲空间

:heap_final_num - 终结器插槽号码



通过增加 RUBY_MIN_HEAP_SLOTS 堆的数量应该减少到一个。但是更高的 RUBY_FREE_MIN 你会得到更多的堆。它表示当前堆应该有空闲插槽的数量,如果该数量小于您提供的数量 - ruby​​会创建新的堆。
RUBY_GC_MALLOC_LIMIT 与ruby运行GC进程的频率有关,并且不会直接影响堆号。这个计数器表示在ruby运行GC之后有多少个malloc。但它可以更早地被毁掉。请注意,它不是ruby obj分配,它是全局ruby内部malloc计数器,在任何ruby解释器内部obj分配上都会增加。


I am using GC.stat to profile memory usage in our Rails app. GC.stat returns a hash with the following keys:

:count
:heap_used
:heap_length
:heap_increment
:heap_live_num
:heap_free_num
:heap_final_num

Does anybody know exactly what these values mean? There's no documentation of them in the Ruby source (gc.c), just a comment: "The contents of the hash are implementation defined and may be changed in the future."

Some of these fields make sense from context, e.g. count is the number of heaps Ruby has allocated. But what is heap_final_num? What is heap_increment? Is heap_length the minimum heap size?

I'm fiddling with RUBY_MIN_HEAP_SLOTS, RUBY_FREE_MIN and RUBY_GC_MALLOC_LIMIT, but changing those env vars doesn't seem to have any effect on :heap_count or :heap_length. I would expect that :heap_count would go down if I radically increase min heap slots. So I really would like to know exactly what all the GC.stat values represent!

I'm using Ruby 1.9.3.

解决方案

:count - the number of gc cycles, e.g. how many times did gc run

:heap_used - the number of allocated heaps, ruby creates one heap by default and increase heap number if it's not enough to allocate all objects

:heap_length - the size of the heap. That's the first heap size. Ideally you should have one heap after script start

:heap_increment - the number that would be added to the last heap size if ruby creates new heap

:heap_live_num - how many heap slots are allocated

:heap_free_num - how many heap slots are free

:heap_final_num - finalizers slots number

You are right that by increasing RUBY_MIN_HEAP_SLOTS the number of heaps should decrease down to one. But the higher RUBY_FREE_MIN the more heaps you'll get. It indicates the number of free slots that current heap should have, if that number is less than you provided - ruby creates new heap. RUBY_GC_MALLOC_LIMIT is more related to how often ruby would run GC process and does not affect heaps number directly. This counter indicates after how many mallocs ruby would run GC. But it can be runed even earlier. Please note that it's not ruby obj allocations, it's global ruby internal malloc counter that's incremented on any ruby interpreter internal obj allocation.

这篇关于Ruby的GC.stat的字段是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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