summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-10-19 08:41:55 +0200
committerStan Hu <stanhu@gmail.com>2017-10-19 08:44:14 +0200
commitf35e630d3a9f76770e5f4597817e019faa53bbc8 (patch)
tree004fdb397492b59d1a93d1e3fd70f0941978a4a8
parent00c15cc27c33dd387069fce5777beb29d01f55ac (diff)
downloadgitlab-ce-sh-memoize-logger.tar.gz
Memoize GitLab logger to reduce open file descriptorssh-memoize-logger
We see that in gitlab-org/gitlab-ee#3664 that if we log a lot of data in Sidekiq workers, the number of open file descriptors reaches over 1000. To avoid this, we can memoize the logger per thread via RequestStore. Closes gitlab-org/gitlab-ee#3664
-rw-r--r--changelogs/unreleased/sh-memoize-logger.yml5
-rw-r--r--lib/gitlab/logger.rb8
2 files changed, 11 insertions, 2 deletions
diff --git a/changelogs/unreleased/sh-memoize-logger.yml b/changelogs/unreleased/sh-memoize-logger.yml
new file mode 100644
index 00000000000..1b6567ce72f
--- /dev/null
+++ b/changelogs/unreleased/sh-memoize-logger.yml
@@ -0,0 +1,5 @@
+---
+title: Memoize GitLab logger to reduce open file descriptors
+merge_request:
+author:
+type: fixed
diff --git a/lib/gitlab/logger.rb b/lib/gitlab/logger.rb
index 6bffd410ed0..dd88da73e91 100644
--- a/lib/gitlab/logger.rb
+++ b/lib/gitlab/logger.rb
@@ -13,7 +13,7 @@ module Gitlab
end
def self.read_latest
- path = Rails.root.join("log", file_name)
+ path = self.full_log_path
return [] unless File.readable?(path)
@@ -22,7 +22,11 @@ module Gitlab
end
def self.build
- new(Rails.root.join("log", file_name))
+ RequestStore[self.full_log_path] ||= new(self.full_log_path)
+ end
+
+ def self.full_log_path
+ Rails.root.join("log", file_name)
end
end
end