From: "Eregon (Benoit Daloze) via ruby-core" Date: 2023-03-10T15:19:20+00:00 Subject: [ruby-core:112844] [Ruby master Feature#19435] Expose counts for each GC reason in GC.stat Issue #19435 has been updated by Eregon (Benoit Daloze). byroot (Jean Boussier) wrote in #note-6: > > matz: stat gets bloated is kind of worrying. > > I'm not too concerned about this, it's an advanced API for instrumentation purposes, and the doc clearly state: "The contents of the hash are implementation specific and may be changed in the future.". Rails calls `GC.stat(:total_allocated_objects)` on every request (https://github.com/rails/rails/blob/2eed4dc0afd1b82b2c12c6f77ab7271e72699168/activesupport/lib/active_support/notifications/instrumenter.rb#L220), so one thing to keep in mind is not slowing down accessing just one value of GC.stat. ---------------------------------------- Feature #19435: Expose counts for each GC reason in GC.stat https://bugs.ruby-lang.org/issues/19435#change-102356 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal ---------------------------------------- ### Context We recently tuned the GC settings on our monolith application because we were seeing some very long GC pauses (multiple seconds) during some requests. Very early we realized that we could know how often the GC was triggered, and how long it was taking, but we had no information as to why, hence no good way to know which specific configuration to tune. As of today, the only way to get this information is to compile Ruby with debug counters, but that's not really accessible for most users, and not very suitable to be deployed in production. So we patched our Ruby to expose counters for each specific reason in `GC.stat` and this data was extremely valuable. For instance we discovered that the number 1 cause of major GC was `shady` objects, which allowed us to both better tune or GC and to drive some targeted patches to Ruby. ### Proposal We'd like to merge the patch we used on our Ruby build. It expose 8 new keys in `GC.stat`: - `:major_gc_nofree_count` - `:major_gc_oldgen_count` - `:major_gc_shady_count` - `:major_gc_newobj_count` - `:major_gc_malloc_count` - `:major_gc_oldmalloc_count` - `:minor_gc_newobj_count` - `:minor_gc_malloc_count` Some very uncommon reasons like `force` etc are ignored as they're not valuable. Also note that sometimes multiple conditions can be met to trigger GC, in such case we my increment several counters, so the sum of `major_gc_*_count` can be higher than `major_gc_count`. Proposed patch: https://github.com/ruby/ruby/pull/7250 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/