From d991ea6dddaa1ffaab5c9205bdfdc730c24b09b3 Mon Sep 17 00:00:00 2001
From: Stan Hu <stanhu@gmail.com>
Date: Sat, 17 Nov 2018 23:13:00 -0800
Subject: [PATCH] Improve memory performance by reducing dirty pages after
 fork()

The nakayoshi_fork gem works around the lack of a Ruby compacting
garbage collecting by calling GC.start a few times to "promote" the age
of young objects to the maximum age 3. This reduces the number of dirty
pages and consequently improves copy-on-write behavior with unicorn
and other forking Web application servers.
---
 Gemfile                                         | 3 +++
 Gemfile.lock                                    | 2 ++
 Gemfile.rails4.lock                             | 2 ++
 changelogs/unreleased/sh-use-nakayoshi-fork.yml | 5 +++++
 4 files changed, 12 insertions(+)
 create mode 100644 changelogs/unreleased/sh-use-nakayoshi-fork.yml

diff --git a/Gemfile b/Gemfile
index 2a228b326adb..8104ddde61be 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,6 +15,9 @@ source 'https://rubygems.org'
 gem 'rails', gem_versions['rails']
 gem 'rails-deprecated_sanitizer', '~> 1.0.3'
 
+# Improves copy-on-write performance for MRI
+gem 'nakayoshi_fork', '~> 0.0.4'
+
 # Responders respond_to and respond_with
 gem 'responders', '~> 2.0'
 
diff --git a/Gemfile.lock b/Gemfile.lock
index e21a1b854574..84137fbfa6c0 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -470,6 +470,7 @@ GEM
     mustermann-grape (1.0.0)
       mustermann (~> 1.0.0)
     mysql2 (0.4.10)
+    nakayoshi_fork (0.0.4)
     net-ldap (0.16.0)
     net-ssh (5.0.1)
     netrc (0.11.0)
@@ -1051,6 +1052,7 @@ DEPENDENCIES
   mini_magick
   minitest (~> 5.7.0)
   mysql2 (~> 0.4.10)
+  nakayoshi_fork (~> 0.0.4)
   net-ldap
   net-ssh (~> 5.0)
   nokogiri (~> 1.8.2)
diff --git a/Gemfile.rails4.lock b/Gemfile.rails4.lock
index fea3102b8d6c..8ca5f114af82 100644
--- a/Gemfile.rails4.lock
+++ b/Gemfile.rails4.lock
@@ -467,6 +467,7 @@ GEM
     mustermann-grape (1.0.0)
       mustermann (~> 1.0.0)
     mysql2 (0.4.10)
+    nakayoshi_fork (0.0.4)
     net-ldap (0.16.0)
     net-ssh (5.0.1)
     netrc (0.11.0)
@@ -1042,6 +1043,7 @@ DEPENDENCIES
   mini_magick
   minitest (~> 5.7.0)
   mysql2 (~> 0.4.10)
+  nakayoshi_fork (~> 0.0.4)
   net-ldap
   net-ssh (~> 5.0)
   nokogiri (~> 1.8.2)
diff --git a/changelogs/unreleased/sh-use-nakayoshi-fork.yml b/changelogs/unreleased/sh-use-nakayoshi-fork.yml
new file mode 100644
index 000000000000..5977d9b0974b
--- /dev/null
+++ b/changelogs/unreleased/sh-use-nakayoshi-fork.yml
@@ -0,0 +1,5 @@
+---
+title: Improve memory performance by reducing dirty pages after fork()
+merge_request: 23169
+author:
+type: performance
-- 
GitLab