diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-07-09 13:24:33 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-07-09 17:06:15 +0300 |
commit | 580368c09b5f9f243b5ec8e271359d6a4ac8c398 (patch) | |
tree | 4f8c7d5fe8e3fe83b9785ed9f3aac082941aadf0 /lib/gitlab/metrics/samplers/unicorn_sampler.rb | |
parent | 12422dbf10a1fca27b6f3c51224d3bb25ed173ed (diff) |
Make unicorn_workers to return meaningful results
Diffstat (limited to 'lib/gitlab/metrics/samplers/unicorn_sampler.rb')
-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 |