86

I suppose it's a pretty trivial question but nevertheless, I'm looking for the (sacct I guess) command that will display the CPU time and memory used by a slurm job ID.

user1701545
  • 5,706
  • 14
  • 49
  • 80

7 Answers7

87

If your job is finished, then the sacct command is what you're looking for. Otherwise, look into sstat. For sacct the --format switch is the other key element. If you run this command:

sacct -e

you'll get a printout of the different fields that can be used for the --format switch. The details of each field are described in the Job Account Fields section of the man page. For CPU time and memory, CPUTime and MaxRSS are probably what you're looking for. cputimeraw can also be used if you want the number in seconds, as opposed to the usual Slurm time format.

sacct --format="CPUTime,MaxRSS"
aaron.kizmiller
  • 886
  • 7
  • 2
  • 14
    Just a note for people that land here searching for real time… use `Elapsed` instead (+1). – Sparhawk Jun 06 '16 at 04:00
  • 7
    The value returned for `CPUTime` is always the value of `NCPUS` * `Elapsed`. To get stats about real CPU usage you need to look at `SystemCPU` and `UserCPU`, but the docs warns that it only measure CPU time for the parent process and not for child processes. – Jean Paul Apr 25 '17 at 14:49
  • 6
    MaxRSS seems to always be empty for running tasks (at least for me). Is there some other option / other way to get some estimate on a running task's memory. – Kvothe Feb 14 '19 at 10:49
  • 1
    What decides whether a job is still shown in sacct. It seems it does not show data on old jobs? – Kvothe Sep 04 '19 at 10:21
  • How can I retrieve `SystemCPU and UserCPU` should I use `acct`? – alper Jan 22 '21 at 14:12
  • Any idea why `sacct -u username` does not work for other users? Even while being admin. – Naeem Khoshnevis Feb 09 '21 at 23:19
71

The other answers all detail formats for output of sacct, which is great for looking at multiple jobs aggregated in a table.

However, sometimes you want to look at a specific job in more detail, so you can tell whether your job efficiently used the allocated resources. For that, seff is very useful. The syntax is simply seff <Jobid>. For example, here's a recent job of mine (that failed):

$ seff 15780625

Job ID: 15780625
Cluster: mycluster
User/Group: myuser/mygroup
State: OUT_OF_MEMORY (exit code 0)
Nodes: 1
Cores per node: 16
CPU Utilized: 12:06:01
CPU Efficiency: 85.35% of 14:10:40 core-walltime
Job Wall-clock time: 00:53:10
Memory Utilized: 1.41 GB
Memory Efficiency: 70.47% of 2.00 GB

Note that the key CPU metric, CPU Utilized, corresponds to the TotalCPU field from sacct, while Memory Utilized corresponds to MaxRSS.

SpinUp __ A Davis
  • 5,016
  • 1
  • 30
  • 25
  • is there also a way to retrieve average RSS, or a time series of the memory usage over the life of the job? – Rylan Schaeffer Aug 04 '20 at 15:48
  • @RylanSchaeffer Use AveRSS rather than MaxRSS – SpinUp __ A Davis Aug 05 '20 at 14:50
  • How do I do that? Is that Memory Efficiency? – Rylan Schaeffer Aug 05 '20 at 15:30
  • @RylanSchaeffer Please post a new question with the details of what you're trying to achieve (Use the "Ask Question" button at the top of the page, not the comments) – SpinUp __ A Davis Aug 05 '20 at 18:03
  • I did yesterday https://stackoverflow.com/questions/63250581/find-cpu-and-memory-time-series-of-slurm-job – Rylan Schaeffer Aug 05 '20 at 18:48
  • Comments are fine for clarifying. Your answer of specifying *what* to use without specifying *how* to use it isn't helpful – Rylan Schaeffer Aug 05 '20 at 18:48
  • 17
    Is seff standard on slurm managed clusters? It isn't finding that command for me. – Kvothe Feb 02 '21 at 17:05
  • @Kvothe Sorry, I don't know -- it wasn't something I added, it was installed on the one I use – SpinUp __ A Davis Feb 05 '21 at 20:28
  • 5
    How/where can I install `seff`? – alper Nov 07 '21 at 17:41
  • @alper It appears to have been added to Slurm [circa 2015](https://bugs.schedmd.com/show_bug.cgi?id=1611), so it's probably something to ask your cluster administrator about – SpinUp __ A Davis Nov 09 '21 at 16:27
  • I am using slurm by myself unfortunetly there is not administrator to ask about. I clone slurm from its github repo and compiled it using: `./configure --enable-debug --enable-front-end` but there is not `seff ` binary is installed – alper Nov 09 '21 at 19:43
  • I haven't installed it myself so I'm not much help -- the only advice I could give would be to check out the `seff` tarball attached to the thread that I linked, or ask a separate question, either here or on the slurm forums – SpinUp __ A Davis Nov 10 '21 at 16:38
  • Is there a way to automatically print the seff output in the output file generated during the job? I previously used a PBS job scheduler which produced similar output by default at the end of the output files requested in the PBS job scheduler. I'm looking for the SLURM equivalent – Bob Mar 30 '22 at 16:21
  • 1
    @SpinUp__ADavis im trying to understand how your job died from insufficient memroy when 'memory utilized' (1.41G) is quite a bit less than allocated (2G), and utilization was only 70%. In my case a job died with an even bigger spread - 10M or .52% of 2G. would like to know the amount of memory i need to request but doesnt seem this will get me there. – aknodt Jun 17 '23 at 23:09
  • 1
    @aknodt Other sources indicate that the accounting mechanism is [polling based](https://stackoverflow.com/a/64544070/1329892), so it might not catch spikes in memory usage before the job gets killed for OOM. I think the most straightforward way is to allocate much more memory to a job than you think you'll need, and kill it if necessary once it's fully underway, then go back and look at Memory Utilized to get a better sense of the upper limit you can get away with. – SpinUp __ A Davis Jun 23 '23 at 17:07
34

sacct is indeed the command to use for finished jobs. For running jobs, you can look at the sstat command.

damienfrancois
  • 52,978
  • 9
  • 96
  • 110
21

@aaron.kizmiller is right, sacct is the command to use.

One can fetch all of the following fields by passing them into saact --format="field,field"

Fields:

Account           AdminComment      AllocCPUS         AllocGRES
AllocNodes        AllocTRES         AssocID           AveCPU
AveCPUFreq        AveDiskRead       AveDiskWrite      AvePages
AveRSS            AveVMSize         BlockID           Cluster
Comment           ConsumedEnergy    ConsumedEnergyRaw CPUTime
CPUTimeRAW        DerivedExitCode   Elapsed           ElapsedRaw
Eligible          End               ExitCode          GID
Group             JobID             JobIDRaw          JobName
Layout            MaxDiskRead       MaxDiskReadNode   MaxDiskReadTask
MaxDiskWrite      MaxDiskWriteNode  MaxDiskWriteTask  MaxPages
MaxPagesNode      MaxPagesTask      MaxRSS            MaxRSSNode
MaxRSSTask        MaxVMSize         MaxVMSizeNode     MaxVMSizeTask
McsLabel          MinCPU            MinCPUNode        MinCPUTask
NCPUS             NNodes            NodeList          NTasks
Priority          Partition         QOS               QOSRAW
ReqCPUFreq        ReqCPUFreqMin     ReqCPUFreqMax     ReqCPUFreqGov
ReqCPUS           ReqGRES           ReqMem            ReqNodes
ReqTRES           Reservation       ReservationId     Reserved
ResvCPU           ResvCPURAW        Start             State
Submit            Suspended         SystemCPU         Timelimit
TotalCPU          UID               User              UserCPU
WCKey             WCKeyID           WorkDir

For example, to list all job ids, elapsed time, and max VM size, you can run:

sacct --format='JobID,Elapsed,MaxVMSize'

duhaime
  • 25,611
  • 17
  • 169
  • 224
  • Thus, if I want to know how many SBU I have used, I should run: `sacct -ojobid,state,cputime` To get a jobID, the sate and the actual amount of SBU I have used ? – runlevel0 May 27 '19 at 09:21
6

Although there already exist fantastic solutions, I share an another perspective.

This method can do the real time monitoring of a lot of nodes.

We can write a script monitor.sh to obtain the statistic(memory as an example), then logged it into file.

#! /bin/sh
if [ -f "./free.log_"`hostname` ];then
    echo "file existed , now deleting it !"
    rm ./free.log_`hostname`
fi
echo "start recording!"

while true
do
    echo "******["`date +%Y-%m-%d_%H:%M:%S`"]******" >> free.log_`hostname`
    free -s 1 -c 2 -h|sed -n 1,2p >> free.log_`hostname`
done

Then write your job script sbatch_input.sh, which can be called by sbatch.

#! /bin/sh
#SBATCH -N 2
#SBATCH -p cnall
srun hostname
srun ./monitor.sh

Call the script

sbatch ./sbatch_input.sh

We can see some log generated.

Xu Hui
  • 1,213
  • 1
  • 11
  • 24
  • Great suggestion, thanks! How should I do this alongside my actual job? Should I just include the extra `srun ./monitor.sh` on my original sbatch call, or should I create another call? – kaslusimoes Apr 01 '21 at 09:58
5

You can export SACCT_FORMAT and just type sacct every time.

$ export SACCT_FORMAT="JobID%20,JobName,User,Partition,NodeList,Elapsed,CPUTime,State,AllocTRES%32"
$ sacct
               JobID    JobName      User  Partition        NodeList    Elapsed    CPUTime      State                        AllocTRES 
-------------------- ---------- --------- ---------- --------------- ---------- ---------- ---------- -------------------------------- 
            249527_4   xgb_tune    zhaoqi         cn            cn12   00:26:50 1-11:46:40    RUNNING billing=80,cpu=80,mem=100G,node+ 
            249527_1   xgb_tune    zhaoqi         cn            cn09   00:26:50 1-11:46:40    RUNNING billing=80,cpu=80,mem=100G,node+ 
            249527_2   xgb_tune    zhaoqi         cn            cn10   00:26:50 1-11:46:40    RUNNING billing=80,cpu=80,mem=100G,node+ 
            249527_3   xgb_tune    zhaoqi         cn            cn11   00:26:50 1-11:46:40    RUNNING billing=80,cpu=80,mem=100G,node+ 

ref: https://docs.ycrc.yale.edu/clusters-at-yale/job-scheduling/resource-usage/

Shixiang Wang
  • 2,147
  • 2
  • 24
  • 33
2
sacct -a -j <job_id> --format=user%10,jobname%10,node%10,start%10,end%10,elapsed%10,MaxRS

use the command sacct to access finished slurm job history

for <job_id>, it's referring to the slurm job id then, this --format= to mention the different details to display, with which format:

  • the user: the user run the job
  • the jobname: the job or process name
  • the node: this to indicate in which machine the job was done
  • the start and end are indicating successively the job start and end dates
  • for elapsed it's about the runtime of job or process,
  • and MaxRS for max cpus used to get the job done
  • for % it's used to determine how much characters to dedicated for printing a given info (e.g jobname%25: Jobname will be displayed in 25 characters)
Nour
  • 41
  • 5
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel May 08 '22 at 11:58