Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-16 21:09:15 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-16 21:09:15 +0300
commit6d9c4dc2ef4c63bee8e9ca095dc2f0ed683a34f5 (patch)
treeb083ae707edc38dd5e61184ec7e9c6a4aba0f9e7 /doc/development/performance.md
parent01a8b31afeac9ac1eaf64d781de5ee8f15eb1897 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/performance.md')
-rw-r--r--doc/development/performance.md34
1 files changed, 34 insertions, 0 deletions
diff --git a/doc/development/performance.md b/doc/development/performance.md
index 6ba7a17041e..e20633a05f6 100644
--- a/doc/development/performance.md
+++ b/doc/development/performance.md
@@ -349,6 +349,40 @@ issues in our code.
## Memory profiling
+We can use two approaches, often in combination, to track down memory issues:
+
+- Leaving the code intact and wrapping a profiler around it.
+- Monitor memory usage of the process while disabling/enabling different parts of the code we suspect could be problematic.
+
+### Using Memory Profiler
+
+We can use `memory_profiler` for profiling.
+
+The [`memory_profiler`](https://github.com/SamSaffron/memory_profiler) gem is already present in GitLab's `Gemfile`,
+you just need to require it:
+
+```ruby
+require 'sidekiq/testing'
+
+report = MemoryProfiler.report do
+ # Code you want to profile
+end
+
+output = File.open('/tmp/profile.txt','w')
+report.pretty_print(output)
+```
+
+The report breaks down 2 key concepts:
+
+- Retained: long lived memory use and object count retained due to the execution of the code block.
+- Allocated: all object allocation and memory allocation during code block.
+
+As a general rule, **retained** will always be smaller than or equal to allocated.
+
+The actual RSS cost will always be slightly higher as MRI heaps are not squashed to size and memory fragments.
+
+### Rbtrace
+
One of the reasons of the increased memory footprint could be Ruby memory fragmentation.
To diagnose it, you can visualize Ruby heap as described in [this post by Aaron Patterson](https://tenderlovemaking.com/2017/09/27/visualizing-your-ruby-heap.html).