[ARVADOS] created: 1.1.1-58-ge9ce829

Git user git at public.curoverse.com
Thu Nov 30 15:45:53 EST 2017


        at  e9ce829350cf4beddc52f0a2c0312151b47b9026 (commit)


commit e9ce829350cf4beddc52f0a2c0312151b47b9026
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu Nov 30 15:45:25 2017 -0500

    12573: Translate Arvados priority to slurm niceness.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
index 30cbb79..f379099 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
@@ -151,6 +151,16 @@ func checkSqueueForOrphans(dispatcher *dispatch.Dispatcher, sqCheck *SqueueCheck
 	}
 }
 
+func niceness(priority int) int {
+	if priority > 1000 {
+		priority = 1000
+	}
+	if priority < 0 {
+		priority = 0
+	}
+	return (1000 - priority) * 1000
+}
+
 // sbatchCmd
 func sbatchFunc(container arvados.Container) *exec.Cmd {
 	mem := int64(math.Ceil(float64(container.RuntimeConstraints.RAM+container.RuntimeConstraints.KeepCacheRAM) / float64(1048576)))
@@ -169,6 +179,7 @@ func sbatchFunc(container arvados.Container) *exec.Cmd {
 	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))
+	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--nice=%d", niceness(container.Priority)))
 	if len(container.SchedulingParameters.Partitions) > 0 {
 		sbatchArgs = append(sbatchArgs, fmt.Sprintf("--partition=%s", strings.Join(container.SchedulingParameters.Partitions, ",")))
 	}
@@ -181,9 +192,15 @@ func scancelFunc(container arvados.Container) *exec.Cmd {
 	return exec.Command("scancel", "--name="+container.UUID)
 }
 
+// scontrolCmd
+func scontrolFunc(container arvados.Container) *exec.Cmd {
+	return exec.Command("scontrol", "update", "JobName="+container.UUID, fmt.Sprintf("--nice=%d", niceness(container.Priority)))
+}
+
 // Wrap these so that they can be overridden by tests
 var sbatchCmd = sbatchFunc
 var scancelCmd = scancelFunc
+var scontrolCmd = scontrolFunc
 
 // Submit job to slurm using sbatch.
 func submit(dispatcher *dispatch.Dispatcher, container arvados.Container, crunchRunCommand []string) error {
@@ -277,6 +294,9 @@ func run(disp *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados
 			} else if updated.Priority == 0 {
 				log.Printf("Container %s has state %q, priority %d: cancel slurm job", ctr.UUID, updated.State, updated.Priority)
 				scancel(ctr)
+			} else if niceness(updated.Priority) != sqCheck.GetNiceness(ctr.UUID) {
+				// dynamically adjust priority
+				scontrolUpdate(updated)
 			}
 		}
 	}
@@ -297,6 +317,21 @@ func scancel(ctr arvados.Container) {
 	}
 }
 
+func scontrolUpdate(ctr arvados.Container) {
+	sqCheck.L.Lock()
+	cmd := scontrolCmd(ctr)
+	msg, err := cmd.CombinedOutput()
+	sqCheck.L.Unlock()
+
+	if err != nil {
+		log.Printf("%q %q: %s %q", cmd.Path, cmd.Args, err, msg)
+		time.Sleep(time.Second)
+	} else if sqCheck.HasUUID(ctr.UUID) {
+		log.Printf("Container %s priority is now %v, niceness is now %v",
+			ctr.UUID, ctr.Priority, sqCheck.GetNiceness(ctr.UUID))
+	}
+}
+
 func readConfig(dst interface{}, path string) error {
 	err := config.LoadFile(dst, path)
 	if err != nil && os.IsNotExist(err) && path == defaultConfigPath {
diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
index 5879f84..58af4a3 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
@@ -71,7 +71,7 @@ func (s *TestSuite) TestIntegrationNormal(c *C) {
 			if done {
 				return exec.Command("true")
 			} else {
-				return exec.Command("echo", "zzzzz-dz642-queuedcontainer")
+				return exec.Command("echo", "zzzzz-dz642-queuedcontainer 999000")
 			}
 		},
 		nil,
@@ -96,7 +96,7 @@ func (s *TestSuite) TestIntegrationCancel(c *C) {
 			if cmd != nil && cmd.ProcessState != nil {
 				return exec.Command("true")
 			} else {
-				return exec.Command("echo", "zzzzz-dz642-queuedcontainer")
+				return exec.Command("echo", "zzzzz-dz642-queuedcontainer 999000")
 			}
 		},
 		func(container arvados.Container) *exec.Cmd {
@@ -131,7 +131,8 @@ func (s *TestSuite) TestIntegrationMissingFromSqueue(c *C) {
 			fmt.Sprintf("--job-name=%s", "zzzzz-dz642-queuedcontainer"),
 			fmt.Sprintf("--mem=%d", 11445),
 			fmt.Sprintf("--cpus-per-task=%d", 4),
-			fmt.Sprintf("--tmp=%d", 45777)},
+			fmt.Sprintf("--tmp=%d", 45777),
+			fmt.Sprintf("--nice=%d", 999000)},
 		func(dispatcher *dispatch.Dispatcher, container arvados.Container) {
 			dispatcher.UpdateState(container.UUID, dispatch.Running)
 			time.Sleep(3 * time.Second)
@@ -204,6 +205,14 @@ func (s *TestSuite) integrationTest(c *C,
 	}(scancelCmd)
 	scancelCmd = newScancelCmd
 
+	// Override scontrol
+	defer func(orig func(arvados.Container) *exec.Cmd) {
+		scontrolCmd = orig
+	}(scontrolCmd)
+	scontrolCmd = func(container arvados.Container) *exec.Cmd {
+		return exec.Command("true")
+	}
+
 	// There should be one queued container
 	params := arvadosclient.Dict{
 		"filters": [][]string{{"state", "=", "Queued"}},
@@ -377,25 +386,32 @@ func (s *MockArvadosServerSuite) TestSbatchFuncWithConfigArgs(c *C) {
 func testSbatchFuncWithArgs(c *C, args []string) {
 	theConfig.SbatchArguments = append(theConfig.SbatchArguments, args...)
 
-	container := arvados.Container{UUID: "123", RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 2}}
+	container := arvados.Container{
+		UUID:               "123",
+		RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 2},
+		Priority:           1}
 	sbatchCmd := sbatchFunc(container)
 
 	var expected []string
 	expected = append(expected, "sbatch")
 	expected = append(expected, theConfig.SbatchArguments...)
-	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=2", "--tmp=0")
+	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=2", "--tmp=0", "--nice=999000")
 
 	c.Check(sbatchCmd.Args, DeepEquals, expected)
 }
 
 func (s *MockArvadosServerSuite) TestSbatchPartition(c *C) {
 	theConfig.SbatchArguments = nil
-	container := arvados.Container{UUID: "123", RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 1}, SchedulingParameters: arvados.SchedulingParameters{Partitions: []string{"blurb", "b2"}}}
+	container := arvados.Container{
+		UUID:                 "123",
+		RuntimeConstraints:   arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 1},
+		SchedulingParameters: arvados.SchedulingParameters{Partitions: []string{"blurb", "b2"}},
+		Priority:             1}
 	sbatchCmd := sbatchFunc(container)
 
 	var expected []string
 	expected = append(expected, "sbatch")
-	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=1", "--tmp=0", "--partition=blurb,b2")
+	expected = append(expected, "--job-name=123", "--mem=239", "--cpus-per-task=1", "--tmp=0", "--nice=999000", "--partition=blurb,b2")
 
 	c.Check(sbatchCmd.Args, DeepEquals, expected)
 }
diff --git a/services/crunch-dispatch-slurm/squeue.go b/services/crunch-dispatch-slurm/squeue.go
index d22e025..3f73b3c 100644
--- a/services/crunch-dispatch-slurm/squeue.go
+++ b/services/crunch-dispatch-slurm/squeue.go
@@ -6,6 +6,7 @@ package main
 
 import (
 	"bytes"
+	"fmt"
 	"log"
 	"os/exec"
 	"strings"
@@ -17,14 +18,14 @@ import (
 // command 'squeue'.
 type SqueueChecker struct {
 	Period    time.Duration
-	uuids     map[string]bool
+	uuids     map[string]int
 	startOnce sync.Once
 	done      chan struct{}
 	sync.Cond
 }
 
 func squeueFunc() *exec.Cmd {
-	return exec.Command("squeue", "--all", "--format=%j")
+	return exec.Command("squeue", "--all", "--format=%j %y")
 }
 
 var squeueCmd = squeueFunc
@@ -40,7 +41,23 @@ func (sqc *SqueueChecker) HasUUID(uuid string) bool {
 
 	// block until next squeue broadcast signaling an update.
 	sqc.Wait()
-	return sqc.uuids[uuid]
+	_, exists := sqc.uuids[uuid]
+	return exists
+}
+
+// GetNiceness returns the niceness of a given uuid, or -1 if it doesn't exist.
+func (sqc *SqueueChecker) GetNiceness(uuid string) int {
+	sqc.startOnce.Do(sqc.start)
+
+	sqc.L.Lock()
+	defer sqc.L.Unlock()
+
+	n, exists := sqc.uuids[uuid]
+	if exists {
+		return n
+	} else {
+		return -1
+	}
 }
 
 // Stop stops the squeue monitoring goroutine. Do not call HasUUID
@@ -70,10 +87,15 @@ func (sqc *SqueueChecker) check() {
 		return
 	}
 
-	uuids := strings.Split(stdout.String(), "\n")
-	sqc.uuids = make(map[string]bool, len(uuids))
-	for _, uuid := range uuids {
-		sqc.uuids[uuid] = true
+	lines := strings.Split(stdout.String(), "\n")
+	sqc.uuids = make(map[string]int, len(lines))
+	for _, line := range lines {
+		var uuid string
+		var nice int
+		fmt.Sscan(line, &uuid, &nice)
+		if uuid != "" {
+			sqc.uuids[uuid] = nice
+		}
 	}
 	sqc.Broadcast()
 }

commit 1b949ff836696034183c136a1a3540e284bf3e11
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu Nov 30 14:39:41 2017 -0500

    12573: Clamp range of priority to [0,1000] for container & container request.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 83765fb..176ac45 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -24,6 +24,7 @@ class Container < ArvadosModel
   before_validation :fill_field_defaults, :if => :new_record?
   before_validation :set_timestamps
   validates :command, :container_image, :output_path, :cwd, :priority, :presence => true
+  validates :priority, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 1000 }
   validate :validate_state_change
   validate :validate_change
   validate :validate_lock
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index 94e4e1f..178c156 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -23,6 +23,7 @@ class ContainerRequest < ArvadosModel
   before_validation :set_container
   validates :command, :container_image, :output_path, :cwd, :presence => true
   validates :output_ttl, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
+  validates :priority, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 1000 }
   validate :validate_state_change
   validate :check_update_whitelist
   after_save :update_priority
@@ -158,6 +159,7 @@ class ContainerRequest < ArvadosModel
     self.container_count_max ||= Rails.configuration.container_count_max
     self.scheduling_parameters ||= {}
     self.output_ttl ||= 0
+    self.priority ||= 500
   end
 
   def set_container
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index e751d61..1744584 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -41,7 +41,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
     cr = create_minimal_req!
 
     assert_nil cr.container_uuid
-    assert_nil cr.priority
+    assert_equal 500, cr.priority
 
     check_bogus_states cr
 
@@ -109,6 +109,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
   test "Container request priority must be non-nil" do
     set_user_from_auth :active
     cr = create_minimal_req!(priority: nil)
+    cr.priority = nil
     cr.state = "Committed"
     assert_raises(ActiveRecord::RecordInvalid) do
       cr.save!
@@ -774,4 +775,35 @@ class ContainerRequestTest < ActiveSupport::TestCase
       assert_nothing_raised {cr.destroy}
     end
   end
+
+  test "Container request valid priority" do
+    set_user_from_auth :active
+    cr = create_minimal_req!
+
+    assert_raises(ActiveRecord::RecordInvalid) do
+      cr.priority = -1
+      cr.save!
+    end
+
+    cr.priority = 0
+    cr.save!
+
+    cr.priority = 1
+    cr.save!
+
+    cr.priority = 500
+    cr.save!
+
+    cr.priority = 999
+    cr.save!
+
+    cr.priority = 1000
+    cr.save!
+
+    assert_raises(ActiveRecord::RecordInvalid) do
+      cr.priority = 1001
+      cr.save!
+    end
+  end
+
 end
diff --git a/services/api/test/unit/container_test.rb b/services/api/test/unit/container_test.rb
index 09373fd..ab53240 100644
--- a/services/api/test/unit/container_test.rb
+++ b/services/api/test/unit/container_test.rb
@@ -95,6 +95,42 @@ class ContainerTest < ActiveSupport::TestCase
     end
   end
 
+  test "Container request valid priority" do
+    act_as_system_user do
+      cr, _ = minimal_new(environment: {},
+                      mounts: {"BAR" => "FOO"},
+                      output_path: "/tmp",
+                      priority: 1,
+                      runtime_constraints: {"vcpus" => 1, "ram" => 1})
+
+      assert_raises(ActiveRecord::RecordInvalid) do
+        cr.priority = -1
+        cr.save!
+      end
+
+      cr.priority = 0
+      cr.save!
+
+      cr.priority = 1
+      cr.save!
+
+      cr.priority = 500
+      cr.save!
+
+      cr.priority = 999
+      cr.save!
+
+      cr.priority = 1000
+      cr.save!
+
+      assert_raises(ActiveRecord::RecordInvalid) do
+        cr.priority = 1001
+        cr.save!
+      end
+    end
+  end
+
+
   test "Container serialized hash attributes sorted before save" do
     env = {"C" => 3, "B" => 2, "A" => 1}
     m = {"F" => {"kind" => 3}, "E" => {"kind" => 2}, "D" => {"kind" => 1}}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list