From af88b09d9ed8c29f566e2180b21ee3395d181fbd Mon Sep 17 00:00:00 2001 From: Wedge Date: Sat, 11 Jun 2016 19:03:15 +0300 Subject: [PATCH] Remove newrelic --- .gitignore | 1 + Gemfile | 2 +- Gemfile.lock | 2 - app/jobs/clean_api_defender_statistics_job.rb | 2 + app/jobs/clean_rpm_build_node_job.rb | 2 + config/initializers/1_sidekiq.rb | 51 +++++++++++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ae5f3b5d1..ed62e9001 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ +1.sh .bundle .rvmrc .DS_Store diff --git a/Gemfile b/Gemfile index a0da77e03..acc698b4c 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem 'russian' gem 'state_machines-activerecord' gem 'redis-rails' -gem 'newrelic_rpm' +#gem 'newrelic_rpm' gem 'jbuilder' gem 'sprockets' diff --git a/Gemfile.lock b/Gemfile.lock index 809a6be48..e3ba5cac0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -242,7 +242,6 @@ GEM nest (1.1.2) redis netrc (0.11.0) - newrelic_rpm (3.15.2.317) ng-rails-csrf (0.1.0) ngannotate-rails (1.2.2) execjs @@ -563,7 +562,6 @@ DEPENDENCIES meta-tags meta_request mock_redis - newrelic_rpm ng-rails-csrf ngannotate-rails octokit (~> 4.0) diff --git a/app/jobs/clean_api_defender_statistics_job.rb b/app/jobs/clean_api_defender_statistics_job.rb index cacac0619..78bf9a479 100644 --- a/app/jobs/clean_api_defender_statistics_job.rb +++ b/app/jobs/clean_api_defender_statistics_job.rb @@ -1,6 +1,8 @@ class CleanApiDefenderStatisticsJob include Sidekiq::Worker + sidekiq_options :queue => :low + def perform deadline = Date.today - 1.month Redis.current.keys.select do |key| diff --git a/app/jobs/clean_rpm_build_node_job.rb b/app/jobs/clean_rpm_build_node_job.rb index fb42fda80..51d62b74a 100644 --- a/app/jobs/clean_rpm_build_node_job.rb +++ b/app/jobs/clean_rpm_build_node_job.rb @@ -1,6 +1,8 @@ class CleanRpmBuildNodeJob include Sidekiq::Worker + sidekiq_options :queue => :low + def perform RpmBuildNode.all.each do |n| n.delete unless n.user_id diff --git a/config/initializers/1_sidekiq.rb b/config/initializers/1_sidekiq.rb index d249746b2..550ce8f79 100644 --- a/config/initializers/1_sidekiq.rb +++ b/config/initializers/1_sidekiq.rb @@ -10,3 +10,54 @@ Sidekiq.configure_server do |config| end end +if ENV["PROFILE"] + require "objspace" + ObjectSpace.trace_object_allocations_start + Sidekiq.logger.info "allocations tracing enabled" + + module Sidekiq + module Middleware + module Server + class Profiler + # Number of jobs to process before reporting + JOBS = 100 + + class << self + mattr_accessor :counter + self.counter = 0 + + def synchronize(&block) + @lock ||= Mutex.new + @lock.synchronize(&block) + end + end + + def call(worker_instance, item, queue) + begin + yield + ensure + self.class.synchronize do + self.class.counter += 1 + + if self.class.counter % JOBS == 0 + Sidekiq.logger.info "reporting allocations after #{self.class.counter} jobs" + GC.start + out = File.open("/tmp/heap.json", "w") + ObjectSpace.dump_all(output: out) + out.close + Sidekiq.logger.info "heap saved to heap.json" + end + end + end + end + end + end + end + end + + Sidekiq.configure_server do |config| + config.server_middleware do |chain| + chain.add Sidekiq::Middleware::Server::Profiler + end + end +end \ No newline at end of file