Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to execute sacct to get job historic data for metrics #857

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions lib/ood_core/job/adapters/slurm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,38 @@ def all_squeue_fields
}
end

# Metrics fields requested from a formatted `sacct` call
def sacct_metrics_fields
{
# The user name of the user who ran the job.
user: 'User',
# Job Id for reference
job_id: 'JobId',
# The job's elapsed time.
elapsed: 'Elapsed',
# Minimum required memory for the job
req_mem: 'ReqMem',
# Count of allocated CPUs
alloc_cpus: 'AllocCPUS',
# Number of requested CPUs.
req_cpus: 'ReqCPUS',
# What the timelimit was/is for the job
time_limit: 'Timelimit',
# Displays the job status, or state
state: 'State',
# The sum of the SystemCPU and UserCPU time used by the job or job step
total_cpu: 'TotalCPU',
# Maximum resident set size of all tasks in job.
max_rss: 'MaxRSS',
# The time the job was submitted. In the same format as End.
submit: 'Submit',
# Initiation time of the job. In the same format as End.
start: 'Start',
# Trackable resources. These are the minimum resource counts requested by the job/step at submission time.
req_tres: 'ReqTRES'
}
end

def queues
info_raw = call('scontrol', 'show', 'part', '-o')

Expand Down Expand Up @@ -357,6 +389,30 @@ def nodes
end.compact
end

def sacct_metrics(job_ids, states, from, to)
#https://slurm.schedmd.com/sacct.html
fields = sacct_metrics_fields
args = ['-P'] # Output will be delimited
args.concat ['--delimiter', UNIT_SEPARATOR]
args.concat ['-n'] # No header
args.concat ['--units', 'G'] # Memory units in GB
args.concat ['-o', fields.values.join(',')] # Required data
args.concat ['--state', states.join(',')] unless states.empty? # Filter by these states
args.concat ['-j', job_ids.join(',')] unless job_ids.empty? # Filter by these job ids
args.concat ['-S', from] if from # Filter from This date
args.concat ['-E', to] if to # Filter until this date

metrics = []
StringIO.open(call('sacct', *args)) do |output|
output.each_line do |line|
# Replace blank values with nil
values = line.strip.split(UNIT_SEPARATOR).map{ |value| value.blank? ? nil : value }
metrics << Hash[fields.keys.zip(values)] unless values.empty?
end
end
metrics
end

private
def str_to_queue_info(line)
hsh = line.split(' ').map do |token|
Expand Down Expand Up @@ -699,6 +755,10 @@ def nodes
@slurm.nodes
end

def sacct_metrics(job_ids: [], states: [], from: nil, to: nil)
@slurm.sacct_metrics(job_ids, states, from, to)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have an actual historic_info API on the adapter class itself to mimic and extend the info API.

Not 100% sure on the method signature here, but these are all keywords so it should be OK for now.

Note that this API should probably respond with an array of Info objects (currently returns an array of hashes?).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some changes to return an array of info objects and added support to disable job steps.

Still when job steps are enabled, it will return them as regular info objects. Not sure this is the best approach at this point, but for our use case, we need the steps for memory metrics calculations.


private
# Convert duration to seconds
def duration_in_seconds(time)
Expand Down