SchedMD/slurm — pull request #76 by birc-aeh (2014-06-26 11:02:59+00:00)
Title: Added simple uid cache to squeue

`squeue` has to convert `uid_t` to a `char*` username a *lot*. Once for every line of output(with the default format) and once for *every* comparison when sorting by username. This causes multiple system calls to open and read `/etc/passwd` on standard systems and on my system running YP there were 17 unnecessary entries in strace per line in the output.

You might wan't to reimplement your own version. Mine is brain dead simple, sorts the array for every new entry and never attempts to free memory for usernames.

Since our system is running YP/NIS it is probably especially bad, but here are some quick timings:

[aeh@fe2 bin]$ time squeue | wc -l
2300

real	0m0.451s
user	0m0.061s
sys	0m0.056s
[aeh@fe2 bin]$ time patched_squeue | wc -l
2300

real	0m0.042s
user	0m0.018s
sys	0m0.005s
[aeh@fe2 bin]$ time squeue --sort=u | wc -l
2300

real	0m4.811s
user	0m0.408s
sys	0m0.615s
[aeh@fe2 bin]$ time patched_squeue --sort=u | wc -l
2300

real	0m0.048s
user	0m0.019s
sys	0m0.006s