Expose memory allocations in performance bar
What does this MR do?
References: #330736 (closed)
This MR makes basic memory metrics for each web transaction available in the Performance Bar.
We had already been logging these to application logs, so these metrics aren't new, but they become more visibly exposed in the Perf Bar.
There is no additional overhead for doing this; while we do compute them twice (see caveats section), this computation is merely comparing counters. The underlying metrics are always collected in any environment via a custom Ruby VM patch.
Test it out
The changes are deployed here: https://gitlab-review-mk-perfbar-gp3j0u.gitlab-review.app
Screenshots (strongly suggested)
Performance Bar
Memory details view
Caveats
-
PerfBar and logs will disagree on memory (slightly). Unfortunately I found during testing that
Peek
queries for metrics before we compute them ininstrumentation_helper
. This is because the former polls for data during theprocess_action.action_controller
event (that is just how Peek works), whereas for logging, we collect metrics a little bit later when exiting the web transaction scope. This presents us with a race condition, which is why I hook into the same event as Peek instead to collect these metrics again slightly ahead of time. This also means that PerfBar memory and logged memory will always slightly disagree, with the latter being a more complete figure. I think that's OK as a first iteration. -
MB vs MiB confusion: The PerfBar figures are in "human readable format". It looks like ActiveSupport is interpreting this as
KiB/MiB
(i.e. base 2) but displays it asKB/MB
(i.e. base 10):
[1] pry(main)> ActiveSupport::NumberHelper.number_to_human_size(1000)
=> "1000 Bytes"
[2] pry(main)> ActiveSupport::NumberHelper.number_to_human_size(1024)
=> "1 KB"
This should print 1 KiB
instead. See https://en.wikipedia.org/wiki/Byte#Multiple-byte_units
I decided not to mess with this however, since this is simply how Rails is doing it. It is a known issue with Rails and his been raised numerous times and been rejected by the Rails core team as "won't fix", see for instance https://github.com/rails/rails/pull/7835 and references in that MR.
Does this MR meet the acceptance criteria?
Conformity
-
I have included a changelog entry, or it's not needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.