Skip to content

Expose memory allocations in performance bar

Matthias Käppler requested to merge mk-perfbar-memory into master

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

Screenshot_from_2021-05-17_10-57-18

Memory details view

Screenshot_from_2021-05-17_11-21-05

Caveats

  • PerfBar and logs will disagree on memory (slightly). Unfortunately I found during testing that Peek queries for metrics before we compute them in instrumentation_helper. This is because the former polls for data during the process_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 as KB/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

Availability and Testing

Edited by Matthias Käppler

Merge request reports