Merge branch 'main' into 18842-arv-mount-disk-config
[arvados.git] / lib / dispatchcloud / node_size_test.go
index cdcf4033fcc629317ef0f6edddf799778bf50e5b..86bfbec7b629dc731e309740346dec85a24ae2d7 100644 (file)
@@ -80,7 +80,10 @@ func (*NodeSizeSuite) TestChoose(c *check.C) {
                        "costly": {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
                },
        } {
-               best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu, Containers: arvados.ContainersConfig{ReserveExtraRAM: 268435456}}, &arvados.Container{
+               best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu, Containers: arvados.ContainersConfig{
+                       LocalKeepBlobBuffersPerVCPU: 1,
+                       ReserveExtraRAM:             268435456,
+               }}, &arvados.Container{
                        Mounts: map[string]arvados.Mount{
                                "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)},
                        },
@@ -98,7 +101,30 @@ func (*NodeSizeSuite) TestChoose(c *check.C) {
        }
 }
 
-func (*NodeSizeSuite) TestChoosePreemptable(c *check.C) {
+func (*NodeSizeSuite) TestChooseWithBlobBuffersOverhead(c *check.C) {
+       menu := map[string]arvados.InstanceType{
+               "nearly": {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "small"},
+               "best":   {Price: 3.3, RAM: 8000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
+               "costly": {Price: 4.4, RAM: 12000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
+       }
+       best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu, Containers: arvados.ContainersConfig{
+               LocalKeepBlobBuffersPerVCPU: 16, // 1 GiB per vcpu => 2 GiB
+               ReserveExtraRAM:             268435456,
+       }}, &arvados.Container{
+               Mounts: map[string]arvados.Mount{
+                       "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)},
+               },
+               RuntimeConstraints: arvados.RuntimeConstraints{
+                       VCPUs:        2,
+                       RAM:          987654321,
+                       KeepCacheRAM: 123456789,
+               },
+       })
+       c.Check(err, check.IsNil)
+       c.Check(best.Name, check.Equals, "best")
+}
+
+func (*NodeSizeSuite) TestChoosePreemptible(c *check.C) {
        menu := map[string]arvados.InstanceType{
                "costly":      {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Preemptible: true, Name: "costly"},
                "almost best": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "almost best"},
@@ -154,69 +180,83 @@ func (*NodeSizeSuite) TestChooseGPU(c *check.C) {
                "low_capability": {Price: 2.1, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "low_capability", CUDA: arvados.CUDAFeatures{DeviceCount: 1, HardwareCapability: "8.0", DriverVersion: "11.0"}},
                "best":           {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best", CUDA: arvados.CUDAFeatures{DeviceCount: 1, HardwareCapability: "9.0", DriverVersion: "11.0"}},
                "low_driver":     {Price: 2.1, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "low_driver", CUDA: arvados.CUDAFeatures{DeviceCount: 1, HardwareCapability: "9.0", DriverVersion: "10.0"}},
-               "small":          {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"},
+               "cheap_gpu":      {Price: 2.0, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "cheap_gpu", CUDA: arvados.CUDAFeatures{DeviceCount: 1, HardwareCapability: "8.0", DriverVersion: "10.0"}},
+               "invalid_gpu":    {Price: 1.9, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "invalid_gpu", CUDA: arvados.CUDAFeatures{DeviceCount: 1, HardwareCapability: "12.0.12", DriverVersion: "12.0.12"}},
+               "non_gpu":        {Price: 1.1, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "non_gpu"},
        }
-       best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{
-               Mounts: map[string]arvados.Mount{
-                       "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)},
+
+       type GPUTestCase struct {
+               CUDA             arvados.CUDARuntimeConstraints
+               SelectedInstance string
+       }
+       cases := []GPUTestCase{
+               GPUTestCase{
+                       CUDA: arvados.CUDARuntimeConstraints{
+                               DeviceCount:        1,
+                               HardwareCapability: "9.0",
+                               DriverVersion:      "11.0",
+                       },
+                       SelectedInstance: "best",
                },
-               RuntimeConstraints: arvados.RuntimeConstraints{
-                       VCPUs:                  2,
-                       RAM:                    987654321,
-                       KeepCacheRAM:           123456789,
-                       CUDADeviceCount:        1,
-                       CUDAHardwareCapability: "9.0",
-                       CUDADriverVersion:      "11.0",
+               GPUTestCase{
+                       CUDA: arvados.CUDARuntimeConstraints{
+                               DeviceCount:        2,
+                               HardwareCapability: "9.0",
+                               DriverVersion:      "11.0",
+                       },
+                       SelectedInstance: "costly",
                },
-       })
-       c.Check(err, check.IsNil)
-       c.Check(best.Name, check.Equals, "best")
-       c.Check(best.RAM >= 1234567890, check.Equals, true)
-       c.Check(best.VCPUs >= 2, check.Equals, true)
-       c.Check(best.CUDA.DeviceCount >= 1, check.Equals, true)
-       c.Check(best.CUDA.DriverVersion, check.Equals, "11.0")
-       c.Check(best.CUDA.HardwareCapability, check.Equals, "9.0")
-
-       best, err = ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{
-               Mounts: map[string]arvados.Mount{
-                       "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)},
+               GPUTestCase{
+                       CUDA: arvados.CUDARuntimeConstraints{
+                               DeviceCount:        1,
+                               HardwareCapability: "8.0",
+                               DriverVersion:      "11.0",
+                       },
+                       SelectedInstance: "low_capability",
                },
-               RuntimeConstraints: arvados.RuntimeConstraints{
-                       VCPUs:                  2,
-                       RAM:                    987654321,
-                       KeepCacheRAM:           123456789,
-                       CUDADeviceCount:        2,
-                       CUDAHardwareCapability: "9.0",
-                       CUDADriverVersion:      "11.0",
+               GPUTestCase{
+                       CUDA: arvados.CUDARuntimeConstraints{
+                               DeviceCount:        1,
+                               HardwareCapability: "9.0",
+                               DriverVersion:      "10.0",
+                       },
+                       SelectedInstance: "low_driver",
                },
-       })
-       c.Check(err, check.IsNil)
-       c.Check(best.Name, check.Equals, "costly")
-       c.Check(best.RAM >= 1234567890, check.Equals, true)
-       c.Check(best.VCPUs >= 2, check.Equals, true)
-       c.Check(best.CUDA.DeviceCount >= 2, check.Equals, true)
-       c.Check(best.CUDA.DriverVersion, check.Equals, "11.0")
-       c.Check(best.CUDA.HardwareCapability, check.Equals, "9.0")
-
-       best, err = ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{
-               Mounts: map[string]arvados.Mount{
-                       "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)},
+               GPUTestCase{
+                       CUDA: arvados.CUDARuntimeConstraints{
+                               DeviceCount:        1,
+                               HardwareCapability: "",
+                               DriverVersion:      "10.0",
+                       },
+                       SelectedInstance: "",
                },
-               RuntimeConstraints: arvados.RuntimeConstraints{
-                       VCPUs:                  2,
-                       RAM:                    987654321,
-                       KeepCacheRAM:           123456789,
-                       CUDADeviceCount:        1,
-                       CUDAHardwareCapability: "8.0",
-                       CUDADriverVersion:      "11.0",
+               GPUTestCase{
+                       CUDA: arvados.CUDARuntimeConstraints{
+                               DeviceCount:        0,
+                               HardwareCapability: "9.0",
+                               DriverVersion:      "11.0",
+                       },
+                       SelectedInstance: "non_gpu",
                },
-       })
-       c.Check(err, check.IsNil)
-       c.Check(best.Name, check.Equals, "low_capability")
-       c.Check(best.RAM >= 1234567890, check.Equals, true)
-       c.Check(best.VCPUs >= 2, check.Equals, true)
-       c.Check(best.CUDA.DeviceCount >= 1, check.Equals, true)
-       c.Check(best.CUDA.DriverVersion, check.Equals, "11.0")
-       c.Check(best.CUDA.HardwareCapability, check.Equals, "8.0")
+       }
 
+       for _, tc := range cases {
+               best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{
+                       Mounts: map[string]arvados.Mount{
+                               "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)},
+                       },
+                       RuntimeConstraints: arvados.RuntimeConstraints{
+                               VCPUs:        2,
+                               RAM:          987654321,
+                               KeepCacheRAM: 123456789,
+                               CUDA:         tc.CUDA,
+                       },
+               })
+               if best.Name != "" {
+                       c.Check(err, check.IsNil)
+                       c.Check(best.Name, check.Equals, tc.SelectedInstance)
+               } else {
+                       c.Check(err, check.Not(check.IsNil))
+               }
+       }
 }