This repository has been archived by the owner on Nov 20, 2019. It is now read-only.
forked from CDLUC3/dashv2
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from CDL-Dryad/passenger-killer
Take out the passenger startup to kill after request and script to kill bloat
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'open3' | ||
require 'byebug' | ||
|
||
module DevOps | ||
class Passenger | ||
|
||
attr_reader :status, :stdout | ||
|
||
BLOATED_MB = 600 | ||
|
||
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 | ||
|
||
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength | ||
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 | ||
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength | ||
|
||
def kill_bloated_pids! | ||
bloated_pids.each do |my_pid| | ||
`kill #{my_pid}` | ||
end | ||
end | ||
|
||
def items_submitting? | ||
StashEngine::RepoQueueState.latest_per_resource.where(state: 'processing') | ||
.where(hostname: StashEngine.repository.class.hostname).count.positive? | ||
end | ||
|
||
end | ||
end |