X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c86cbaa6f286e50900dae3203a42044449e042f7..1885991dd79a75034f7650cccef16ebe3fd71959:/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go index 617b076da2..cca8b3f150 100644 --- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go +++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go @@ -11,6 +11,7 @@ import ( "math" "os" "os/exec" + "regexp" "strings" "time" @@ -122,19 +123,48 @@ func doMain() error { log.Printf("Error notifying init daemon: %v", err) } + go checkSqueueForOrphans(dispatcher, sqCheck) + return dispatcher.Run(context.Background()) } +var containerUuidPattern = regexp.MustCompile(`^[a-z0-9]{5}-dz642-[a-z0-9]{15}$`) + +// Check the next squeue report, and invoke TrackContainer for all the +// containers in the report. This gives us a chance to cancel slurm +// jobs started by a previous dispatch process that never released +// their slurm allocations even though their container states are +// Cancelled or Complete. See https://dev.arvados.org/issues/10979 +func checkSqueueForOrphans(dispatcher *dispatch.Dispatcher, sqCheck *SqueueChecker) { + for _, uuid := range sqCheck.All() { + if !containerUuidPattern.MatchString(uuid) { + continue + } + err := dispatcher.TrackContainer(uuid) + if err != nil { + log.Printf("checkSqueueForOrphans: TrackContainer(%s): %s", uuid, err) + } + } +} + // sbatchCmd func sbatchFunc(container arvados.Container) *exec.Cmd { - memPerCPU := math.Ceil(float64(container.RuntimeConstraints.RAM) / (float64(container.RuntimeConstraints.VCPUs) * 1048576)) + mem := int64(math.Ceil(float64(container.RuntimeConstraints.RAM+container.RuntimeConstraints.KeepCacheRAM) / float64(1048576))) + + var disk int64 + for _, m := range container.Mounts { + if m.Kind == "tmp" { + disk += m.Capacity + } + } + disk = int64(math.Ceil(float64(disk) / float64(1048576))) var sbatchArgs []string - sbatchArgs = append(sbatchArgs, "--share") sbatchArgs = append(sbatchArgs, theConfig.SbatchArguments...) sbatchArgs = append(sbatchArgs, fmt.Sprintf("--job-name=%s", container.UUID)) - sbatchArgs = append(sbatchArgs, fmt.Sprintf("--mem-per-cpu=%d", int(memPerCPU))) + sbatchArgs = append(sbatchArgs, fmt.Sprintf("--mem=%d", mem)) sbatchArgs = append(sbatchArgs, fmt.Sprintf("--cpus-per-task=%d", container.RuntimeConstraints.VCPUs)) + sbatchArgs = append(sbatchArgs, fmt.Sprintf("--tmp=%d", disk)) if len(container.SchedulingParameters.Partitions) > 0 { sbatchArgs = append(sbatchArgs, fmt.Sprintf("--partition=%s", strings.Join(container.SchedulingParameters.Partitions, ","))) }