Merge branch 'wtsi/14110-c-d-s-limit-slurm-concurrency' refs #14110
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Wed, 5 Sep 2018 18:47:19 +0000 (14:47 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Wed, 5 Sep 2018 18:47:19 +0000 (14:47 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
services/crunch-dispatch-slurm/slurm.go

index ce0360261dab4aa3ab424d27c29c782e268b567f..084700d39bfad76b109078f29e81ecf82c40c5be 100644 (file)
@@ -176,7 +176,7 @@ func (disp *Dispatcher) setup() {
        }
        arv.Retries = 25
 
-       disp.slurm = &slurmCLI{}
+       disp.slurm = NewSlurmCLI()
        disp.sqCheck = &SqueueChecker{
                Logger:         disp.logger,
                Period:         time.Duration(disp.PollPeriod),
index 9e9f45270f82d3450d27e380fe63924177e5501d..782be7d8c4e7226ced947bcd26c983ecb6b31de3 100644 (file)
@@ -20,7 +20,15 @@ type Slurm interface {
        Renice(name string, nice int64) error
 }
 
-type slurmCLI struct{}
+type slurmCLI struct{
+       runSemaphore chan bool
+}
+
+func NewSlurmCLI() *slurmCLI {
+       return &slurmCLI{
+              runSemaphore: make(chan bool, 3),
+       }
+}
 
 func (scli *slurmCLI) Batch(script io.Reader, args []string) error {
        return scli.run(script, "sbatch", args)
@@ -64,6 +72,8 @@ func (scli *slurmCLI) Renice(name string, nice int64) error {
 }
 
 func (scli *slurmCLI) run(stdin io.Reader, prog string, args []string) error {
+       scli.runSemaphore <- true
+       defer func() { <-scli.runSemaphore }()
        cmd := exec.Command(prog, args...)
        cmd.Stdin = stdin
        out, err := cmd.CombinedOutput()