summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2018-02-01 18:48:32 +0800
committerLin Jen-Shin <godfat@godfat.org>2018-02-07 22:45:02 +0800
commitd4d564c8e7d2cbc3e6742475a793ba0f630167e3 (patch)
tree4c4b7cf558f37dc8d987dd3533010436a805a858
parent0b9825ca461670941a098a664e997fca04d2d9f9 (diff)
downloadgitlab-ce-d4d564c8e7d2cbc3e6742475a793ba0f630167e3.tar.gz
Try not to hold env and release the controller
after the request. This way, we could release the project referred from the controller, which potentially referred a repository which potentially allocated a lot of memories. Before this change, we could hold the last request data and cannot release the memory. After this change, the largest request data should be able to be collected from GC. This might not impact the instances having heavy load, as the last request should be changing all the time, and GC won't kick in for each request anyway. However it could still potentially allow us to free more memories for each GC runs, because now we could free one more request anyway.
-rw-r--r--config.ru1
-rw-r--r--lib/gitlab/middleware/read_only.rb2
-rw-r--r--lib/gitlab/middleware/release_controller.rb9
-rw-r--r--spec/lib/gitlab/middleware/release_controller_spec.rb20
4 files changed, 31 insertions, 1 deletions
diff --git a/config.ru b/config.ru
index de0400f4f67..c4bef72308e 100644
--- a/config.ru
+++ b/config.ru
@@ -23,5 +23,6 @@ warmup do |app|
end
map ENV['RAILS_RELATIVE_URL_ROOT'] || "/" do
+ use Gitlab::ReleaseController
run Gitlab::Application
end
diff --git a/lib/gitlab/middleware/read_only.rb b/lib/gitlab/middleware/read_only.rb
index c26656704d7..a68c6c3d15c 100644
--- a/lib/gitlab/middleware/read_only.rb
+++ b/lib/gitlab/middleware/read_only.rb
@@ -28,7 +28,7 @@ module Gitlab
end
end
- @app.call(env)
+ @app.call(env).tap { @env = nil }
end
private
diff --git a/lib/gitlab/middleware/release_controller.rb b/lib/gitlab/middleware/release_controller.rb
new file mode 100644
index 00000000000..a21d718d51c
--- /dev/null
+++ b/lib/gitlab/middleware/release_controller.rb
@@ -0,0 +1,9 @@
+module Gitlab
+ module Middleware
+ ReleaseController = Struct.new(:app) do
+ def call(env)
+ app.call(env).tap { env.delete('action_controller.instance') }
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/middleware/release_controller_spec.rb b/spec/lib/gitlab/middleware/release_controller_spec.rb
new file mode 100644
index 00000000000..854bac6e751
--- /dev/null
+++ b/spec/lib/gitlab/middleware/release_controller_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Gitlab::Middleware::ReleaseController do
+ let(:inner_app) { double(:app) }
+ let(:app) { described_class.new(inner_app) }
+ let(:env) { { 'action_controller.instance' => 'something' } }
+
+ before do
+ expect(inner_app).to receive(:call).with(env).and_return('yay')
+ end
+
+ describe '#call' do
+ it 'calls the app and delete the controller' do
+ result = app.call(env)
+
+ expect(result).to eq('yay')
+ expect(env).to be_empty
+ end
+ end
+end