Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Commit

Permalink
Get rid of the request killing after number and made my own task to kill
Browse files Browse the repository at this point in the history
bloated passengers by parsing out info from passenger-status since the feature
that does this costs $2000 a year in the pro version.  We could cron this if we wanted.
Only does it if nothing is currently processing.
  • Loading branch information
sfisher committed Nov 5, 2019
1 parent bc0119e commit ddefe55
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
5 changes: 3 additions & 2 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@
# https://www.phusionpassenger.com/library/config/standalone/reference/#--max-requests-max_requests
execute "cd #{deploy_to}/current; bundle exec passenger start -d --environment #{fetch(:rails_env)} "\
"--pid-file #{fetch(:passenger_pid)} -p #{fetch(:passenger_port)} "\
"--log-file #{fetch(:passenger_log)} --pool-idle-time 86400 --max-pool-size=#{fetch(:passenger_pool)} "\
"--max-requests=500"
"--log-file #{fetch(:passenger_log)} --pool-idle-time 86400 --max-pool-size=#{fetch(:passenger_pool)} "
# "--max-requests=500" -- can't do this since it kills submissions, but we should manually kill if a process gets too
# big and seems to have a memory leak, unfortunately, this feature in passenger is a "pro" feature and isn't free.
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/dev_ops.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'yaml'
require_relative 'dev_ops/passenger'

# rubocop:disable Metrics/BlockLength
namespace :dev_ops do
Expand Down Expand Up @@ -90,5 +91,17 @@ namespace :dev_ops do
exec command
end

desc 'Kill large memory usage passenger processes'
task kill_bloated_passengers: :environment do
passenger = DevOps::Passenger.new

passenger.kill_bloated_pids! unless passenger.items_submitting?

# puts "passenger.status: #{passenger.status}"
# puts "out: \n #{passenger.stdout}"
# puts passenger.bloated_pids
# puts passenger.items_submitting?
end

end
# rubocop:enable Metrics/BlockLength
50 changes: 50 additions & 0 deletions lib/tasks/dev_ops/passenger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'open3'
require 'byebug'

module DevOps
class Passenger

attr_reader :status, :stdout

BLOATED_MB = 600.freeze

def initialize
@stdout, @stderr, @status = Open3.capture3('passenger-status')
@bloated_pids = []
end

def not_running?
@stderr.include?("Phusion Passenger doesn't seem to be running")
end

def bloated_pids
# return (empty) array if not running or return array it is already cached with bloated pids
return @bloated_pids if not_running? || @bloated_pids.length.positive?

process_sections = @stdout.split('* PID: ')
process_sections = process_sections[1..-1] # the second to the last of the split sections

process_sections.each do |section|
matches = section.match(/^(\d+).+Memory *: *(\S+)/m)
pid = matches[1]
memory = 0
memory = matches[2].to_i if matches[2].end_with?('M')
memory = matches[2].to_i * 1000 if matches[2].end_with?('G')
@bloated_pids.push(pid) if memory > BLOATED_MB
end
@bloated_pids
end

def kill_bloated_pids!
bloated_pids.each do |my_pid|
`kill #{my_pid}`
end
end

def items_submitting?
items = StashEngine::RepoQueueState.latest_per_resource.where(state: 'processing')
.where(hostname: StashEngine.repository.class.hostname).count.positive?
end

end
end

0 comments on commit ddefe55

Please sign in to comment.