diff options
author | Stan Hu <stanhu@gmail.com> | 2019-07-09 21:34:03 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-07-09 21:34:03 +0000 |
commit | 306c8caa2c7ac075d10f087a888017e65ea2ad7e (patch) | |
tree | 8ec776228baccfaffd4dea0a035617f9824443b0 /lib | |
parent | 109956a65b873a245b26915eb5f48f40942e4453 (diff) | |
parent | 580368c09b5f9f243b5ec8e271359d6a4ac8c398 (diff) | |
download | gitlab-ce-306c8caa2c7ac075d10f087a888017e65ea2ad7e.tar.gz |
Merge branch 'fix-unicorn-sampler-workers-count' into 'master'
Make unicorn_workers to return meaningful results
Closes #63659
See merge request gitlab-org/gitlab-ce!30506
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/samplers/unicorn_sampler.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/gitlab/metrics/samplers/unicorn_sampler.rb b/lib/gitlab/metrics/samplers/unicorn_sampler.rb index 9af7e0afed4..355f938704e 100644 --- a/lib/gitlab/metrics/samplers/unicorn_sampler.rb +++ b/lib/gitlab/metrics/samplers/unicorn_sampler.rb @@ -54,7 +54,16 @@ module Gitlab end def unicorn_workers_count - `pgrep -f '[u]nicorn_rails worker.+ #{Rails.root.to_s}'`.split.count + http_servers.sum(&:worker_processes) # rubocop: disable CodeReuse/ActiveRecord + end + + # Traversal of ObjectSpace is expensive, on fully loaded application + # it takes around 80ms. The instances of HttpServers are not a subject + # to change so we can cache the list of servers. + def http_servers + return [] unless defined?(::Unicorn::HttpServer) + + @http_servers ||= ObjectSpace.each_object(::Unicorn::HttpServer).to_a end end end |