2018-09-21 21:05:00 +00:00
|
|
|
package scheduler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-11-02 22:59:53 +00:00
|
|
|
"testing"
|
2018-09-21 21:05:00 +00:00
|
|
|
|
2018-11-17 02:32:10 +00:00
|
|
|
"strconv"
|
|
|
|
|
2018-09-21 21:05:00 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
"github.com/hashicorp/nomad/nomad/mock"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-11-15 03:23:38 +00:00
|
|
|
psstructs "github.com/hashicorp/nomad/plugins/shared/structs"
|
2018-09-21 21:05:00 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResourceDistance(t *testing.T) {
|
2018-10-16 23:23:21 +00:00
|
|
|
resourceAsk := &structs.ComparableResources{
|
|
|
|
Flattened: structs.AllocatedTaskResources{
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 2048,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 512,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
MBits: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 4096,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type testCase struct {
|
2018-10-16 23:23:21 +00:00
|
|
|
allocResource *structs.ComparableResources
|
2018-09-21 21:05:00 +00:00
|
|
|
expectedDistance string
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []*testCase{
|
|
|
|
{
|
2018-10-16 23:23:21 +00:00
|
|
|
&structs.ComparableResources{
|
|
|
|
Flattened: structs.AllocatedTaskResources{
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 2048,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 512,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
MBits: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 4096,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"0.000",
|
|
|
|
},
|
|
|
|
{
|
2018-10-16 23:23:21 +00:00
|
|
|
&structs.ComparableResources{
|
|
|
|
Flattened: structs.AllocatedTaskResources{
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1024,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 400,
|
|
|
|
},
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
MBits: 1024,
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 1024,
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
"0.928",
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
{
|
2018-10-16 23:23:21 +00:00
|
|
|
&structs.ComparableResources{
|
|
|
|
Flattened: structs.AllocatedTaskResources{
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 8192,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 200,
|
|
|
|
},
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
MBits: 512,
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 1024,
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
"3.152",
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
{
|
2018-10-16 23:23:21 +00:00
|
|
|
&structs.ComparableResources{
|
|
|
|
Flattened: structs.AllocatedTaskResources{
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 2048,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 500,
|
|
|
|
},
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
MBits: 1024,
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-16 23:23:21 +00:00
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 4096,
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
"0.023",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
2018-10-16 23:23:21 +00:00
|
|
|
actualDistance := fmt.Sprintf("%3.3f", basicResourceDistance(resourceAsk, tc.allocResource))
|
|
|
|
require.Equal(tc.expectedDistance, actualDistance)
|
2018-09-21 21:05:00 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPreemption(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
desc string
|
|
|
|
currentAllocations []*structs.Allocation
|
2018-11-02 22:59:53 +00:00
|
|
|
nodeReservedCapacity *structs.NodeReservedResources
|
|
|
|
nodeCapacity *structs.NodeResources
|
2018-09-21 21:05:00 +00:00
|
|
|
resourceAsk *structs.Resources
|
|
|
|
jobPriority int
|
|
|
|
currentPreemptions []*structs.Allocation
|
|
|
|
preemptedAllocIDs map[string]struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
highPrioJob := mock.Job()
|
|
|
|
highPrioJob.Priority = 100
|
|
|
|
|
|
|
|
lowPrioJob := mock.Job()
|
|
|
|
lowPrioJob.Priority = 30
|
|
|
|
|
|
|
|
lowPrioJob2 := mock.Job()
|
2018-12-08 00:35:47 +00:00
|
|
|
lowPrioJob2.Priority = 40
|
2018-09-21 21:05:00 +00:00
|
|
|
|
|
|
|
// Create some persistent alloc ids to use in test cases
|
2018-12-11 16:12:18 +00:00
|
|
|
allocIDs := []string{uuid.Generate(), uuid.Generate(), uuid.Generate(), uuid.Generate(), uuid.Generate(), uuid.Generate()}
|
2018-09-21 21:05:00 +00:00
|
|
|
|
2018-11-17 02:32:10 +00:00
|
|
|
var deviceIDs []string
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
deviceIDs = append(deviceIDs, "dev"+strconv.Itoa(i))
|
|
|
|
}
|
2018-09-21 21:05:00 +00:00
|
|
|
|
2018-11-02 22:59:53 +00:00
|
|
|
defaultNodeResources := &structs.NodeResources{
|
|
|
|
Cpu: structs.NodeCpuResources{
|
|
|
|
CpuShares: 4000,
|
|
|
|
},
|
|
|
|
Memory: structs.NodeMemoryResources{
|
|
|
|
MemoryMB: 8192,
|
|
|
|
},
|
|
|
|
Disk: structs.NodeDiskResources{
|
|
|
|
DiskMB: 100 * 1024,
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
CIDR: "192.168.0.100/32",
|
|
|
|
MBits: 1000,
|
|
|
|
},
|
|
|
|
},
|
2018-11-15 03:23:38 +00:00
|
|
|
Devices: []*structs.NodeDeviceResource{
|
|
|
|
{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
Attributes: map[string]*psstructs.Attribute{
|
|
|
|
"memory": psstructs.NewIntAttribute(11, psstructs.UnitGiB),
|
|
|
|
"cuda_cores": psstructs.NewIntAttribute(3584, ""),
|
|
|
|
"graphics_clock": psstructs.NewIntAttribute(1480, psstructs.UnitMHz),
|
|
|
|
"memory_bandwidth": psstructs.NewIntAttribute(11, psstructs.UnitGBPerS),
|
|
|
|
},
|
|
|
|
Instances: []*structs.NodeDevice{
|
|
|
|
{
|
|
|
|
ID: deviceIDs[0],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: deviceIDs[1],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: deviceIDs[2],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: deviceIDs[3],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-11-17 02:32:10 +00:00
|
|
|
{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "2080ti",
|
|
|
|
Attributes: map[string]*psstructs.Attribute{
|
|
|
|
"memory": psstructs.NewIntAttribute(11, psstructs.UnitGiB),
|
|
|
|
"cuda_cores": psstructs.NewIntAttribute(3584, ""),
|
|
|
|
"graphics_clock": psstructs.NewIntAttribute(1480, psstructs.UnitMHz),
|
|
|
|
"memory_bandwidth": psstructs.NewIntAttribute(11, psstructs.UnitGBPerS),
|
|
|
|
},
|
|
|
|
Instances: []*structs.NodeDevice{
|
|
|
|
{
|
|
|
|
ID: deviceIDs[4],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: deviceIDs[5],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: deviceIDs[6],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: deviceIDs[7],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
2018-12-11 16:12:18 +00:00
|
|
|
{
|
|
|
|
ID: deviceIDs[8],
|
|
|
|
Healthy: true,
|
|
|
|
},
|
2018-11-17 02:32:10 +00:00
|
|
|
},
|
|
|
|
},
|
2018-11-15 03:23:38 +00:00
|
|
|
{
|
|
|
|
Type: "fpga",
|
|
|
|
Vendor: "intel",
|
|
|
|
Name: "F100",
|
|
|
|
Attributes: map[string]*psstructs.Attribute{
|
|
|
|
"memory": psstructs.NewIntAttribute(4, psstructs.UnitGiB),
|
|
|
|
},
|
|
|
|
Instances: []*structs.NodeDevice{
|
|
|
|
{
|
|
|
|
ID: "fpga1",
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "fpga2",
|
|
|
|
Healthy: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
}
|
2018-11-02 22:59:53 +00:00
|
|
|
|
|
|
|
reservedNodeResources := &structs.NodeReservedResources{
|
|
|
|
Cpu: structs.NodeReservedCpuResources{
|
|
|
|
CpuShares: 100,
|
|
|
|
},
|
|
|
|
Memory: structs.NodeReservedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
Disk: structs.NodeReservedDiskResources{
|
|
|
|
DiskMB: 4 * 1024,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []testCase{
|
|
|
|
{
|
|
|
|
desc: "No preemption because existing allocs are not low priority",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 3200,
|
|
|
|
MemoryMB: 7256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
2018-10-16 23:23:21 +00:00
|
|
|
CPU: 2000,
|
2018-09-21 21:05:00 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "ssh", Value: 22}},
|
|
|
|
MBits: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Preempting low priority allocs not enough to meet resource ask",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 3200,
|
|
|
|
MemoryMB: 7256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 4000,
|
|
|
|
MemoryMB: 8192,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "ssh", Value: 22}},
|
|
|
|
MBits: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-11-01 21:15:58 +00:00
|
|
|
{
|
|
|
|
desc: "preemption impossible - static port needed is used by higher priority alloc",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 1200,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 600,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-11-01 21:15:58 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 600,
|
|
|
|
MemoryMB: 1000,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 700,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-11-02 14:09:50 +00:00
|
|
|
{
|
2018-11-02 21:06:25 +00:00
|
|
|
desc: "preempt only from device that has allocation with unused reserved port",
|
2018-11-02 14:09:50 +00:00
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 1200,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2018-11-02 21:06:25 +00:00
|
|
|
createAlloc(allocIDs[1], highPrioJob, &structs.Resources{
|
2018-11-02 14:09:50 +00:00
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth1",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 600,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 600,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
// This test sets up a node with two NICs
|
2018-11-02 22:59:53 +00:00
|
|
|
nodeCapacity: &structs.NodeResources{
|
|
|
|
Cpu: structs.NodeCpuResources{
|
|
|
|
CpuShares: 4000,
|
|
|
|
},
|
|
|
|
Memory: structs.NodeMemoryResources{
|
|
|
|
MemoryMB: 8192,
|
|
|
|
},
|
|
|
|
Disk: structs.NodeDiskResources{
|
|
|
|
DiskMB: 100 * 1024,
|
|
|
|
},
|
2018-11-02 14:09:50 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
CIDR: "192.168.0.100/32",
|
|
|
|
MBits: 1000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Device: "eth1",
|
|
|
|
CIDR: "192.168.1.100/32",
|
|
|
|
MBits: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 600,
|
|
|
|
MemoryMB: 1000,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 700,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
2018-11-02 21:06:25 +00:00
|
|
|
allocIDs[2]: {},
|
2018-11-02 14:09:50 +00:00
|
|
|
},
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
{
|
|
|
|
desc: "Combination of high/low priority allocs, without static ports",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 2800,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2019-07-03 18:29:47 +00:00
|
|
|
createAllocWithTaskgroupNetwork(allocIDs[1], lowPrioJob, &structs.Resources{
|
2018-09-21 21:05:00 +00:00
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
2019-07-03 18:29:47 +00:00
|
|
|
MBits: 200,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-03 18:29:47 +00:00
|
|
|
}, &structs.NetworkResource{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.201",
|
|
|
|
MBits: 300,
|
2018-09-21 21:05:00 +00:00
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 300,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[3], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 700,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1100,
|
|
|
|
MemoryMB: 1000,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 840,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[1]: {},
|
|
|
|
allocIDs[2]: {},
|
|
|
|
allocIDs[3]: {},
|
|
|
|
},
|
2018-11-01 21:15:58 +00:00
|
|
|
},
|
2019-06-07 22:55:02 +00:00
|
|
|
{
|
|
|
|
desc: "preempt allocs with network devices",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 2800,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 800,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
nodeCapacity: defaultNodeResources,
|
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1100,
|
|
|
|
MemoryMB: 1000,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 840,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[1]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "ignore allocs with close enough priority for network devices",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 2800,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 800,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
nodeCapacity: defaultNodeResources,
|
|
|
|
jobPriority: lowPrioJob.Priority + 5,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1100,
|
|
|
|
MemoryMB: 1000,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 840,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: nil,
|
|
|
|
},
|
2018-11-01 21:15:58 +00:00
|
|
|
{
|
2018-09-21 21:05:00 +00:00
|
|
|
desc: "Preemption needed for all resources except network",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 2800,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 40 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[3], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 700,
|
|
|
|
MemoryMB: 276,
|
|
|
|
DiskMB: 20 * 1024,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 3000,
|
|
|
|
DiskMB: 50 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[1]: {},
|
|
|
|
allocIDs[2]: {},
|
|
|
|
allocIDs[3]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Only one low priority alloc needs to be preempted",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 1200,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 500,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
2018-10-16 23:23:21 +00:00
|
|
|
MBits: 320,
|
2018-09-21 21:05:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 300,
|
|
|
|
MemoryMB: 500,
|
|
|
|
DiskMB: 5 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 320,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[2]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "one alloc meets static port need, another meets remaining mbits needed",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 1200,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 500,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 200,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 2700,
|
|
|
|
MemoryMB: 1000,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 800,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[1]: {},
|
|
|
|
allocIDs[2]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-11-01 21:15:58 +00:00
|
|
|
desc: "alloc that meets static port need also meets other needs",
|
2018-09-21 21:05:00 +00:00
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 1200,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 600,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 600,
|
|
|
|
MemoryMB: 1000,
|
|
|
|
DiskMB: 25 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 700,
|
|
|
|
ReservedPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "db",
|
|
|
|
Value: 88,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[1]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "alloc from job that has existing evictions not chosen for preemption",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 1200,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 500,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob2, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 300,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 300,
|
|
|
|
MemoryMB: 500,
|
|
|
|
DiskMB: 5 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 320,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
currentPreemptions: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[4], lowPrioJob2, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 300,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[1]: {},
|
|
|
|
},
|
|
|
|
},
|
2018-11-15 03:23:38 +00:00
|
|
|
{
|
|
|
|
desc: "Preemption with one device instance per alloc",
|
|
|
|
// Add allocations that use two device instances
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAllocWithDevice(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[0]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[1]},
|
|
|
|
})},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
nodeCapacity: defaultNodeResources,
|
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Devices: []*structs.RequestedDevice{
|
|
|
|
{
|
|
|
|
Name: "nvidia/gpu/1080ti",
|
|
|
|
Count: 4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[0]: {},
|
|
|
|
allocIDs[1]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Preemption multiple devices used",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAllocWithDevice(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[0], deviceIDs[1], deviceIDs[2], deviceIDs[3]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "fpga",
|
|
|
|
Vendor: "intel",
|
|
|
|
Name: "F100",
|
|
|
|
DeviceIDs: []string{"fpga1"},
|
|
|
|
})},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
nodeCapacity: defaultNodeResources,
|
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Devices: []*structs.RequestedDevice{
|
|
|
|
{
|
2018-11-17 02:32:10 +00:00
|
|
|
Name: "nvidia/gpu/1080ti",
|
2018-11-15 03:23:38 +00:00
|
|
|
Count: 4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[0]: {},
|
|
|
|
},
|
|
|
|
},
|
2018-11-17 02:32:10 +00:00
|
|
|
{
|
|
|
|
// This test cases creates allocations across two GPUs
|
|
|
|
// Both GPUs are eligible for the task, but only allocs sharing the
|
|
|
|
// same device should be chosen for preemption
|
|
|
|
desc: "Preemption with allocs across multiple devices that match",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAllocWithDevice(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[0], deviceIDs[1]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[1], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 100,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[2]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "2080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[4], deviceIDs[5]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[3], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 100,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
2018-12-08 00:35:47 +00:00
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "2080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[6], deviceIDs[7]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[4], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "fpga",
|
|
|
|
Vendor: "intel",
|
|
|
|
Name: "F100",
|
|
|
|
DeviceIDs: []string{"fpga1"},
|
|
|
|
})},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
nodeCapacity: defaultNodeResources,
|
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Devices: []*structs.RequestedDevice{
|
|
|
|
{
|
|
|
|
Name: "gpu",
|
|
|
|
Count: 4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[2]: {},
|
|
|
|
allocIDs[3]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// This test cases creates allocations across two GPUs
|
|
|
|
// Both GPUs are eligible for the task, but only allocs with the lower
|
|
|
|
// priority are chosen
|
2018-12-11 16:12:18 +00:00
|
|
|
desc: "Preemption with lower/higher priority combinations",
|
2018-12-08 00:35:47 +00:00
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAllocWithDevice(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[0], deviceIDs[1]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[1], lowPrioJob2, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 100,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[2], deviceIDs[3]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "2080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[4], deviceIDs[5]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[3], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 100,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
2018-11-17 02:32:10 +00:00
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "2080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[6], deviceIDs[7]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[4], lowPrioJob, &structs.Resources{
|
2018-12-11 16:12:18 +00:00
|
|
|
CPU: 100,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "2080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[8]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[5], lowPrioJob, &structs.Resources{
|
2018-11-17 02:32:10 +00:00
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "fpga",
|
|
|
|
Vendor: "intel",
|
|
|
|
Name: "F100",
|
|
|
|
DeviceIDs: []string{"fpga1"},
|
|
|
|
})},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
nodeCapacity: defaultNodeResources,
|
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Devices: []*structs.RequestedDevice{
|
|
|
|
{
|
|
|
|
Name: "gpu",
|
|
|
|
Count: 4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[2]: {},
|
|
|
|
allocIDs[3]: {},
|
|
|
|
},
|
|
|
|
},
|
2018-11-15 03:23:38 +00:00
|
|
|
{
|
|
|
|
desc: "Device preemption not possible due to more instances needed than available",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAllocWithDevice(allocIDs[0], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
DeviceIDs: []string{deviceIDs[0], deviceIDs[1], deviceIDs[2], deviceIDs[3]},
|
|
|
|
}),
|
|
|
|
createAllocWithDevice(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 200,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
}, &structs.AllocatedDeviceResource{
|
|
|
|
Type: "fpga",
|
|
|
|
Vendor: "intel",
|
|
|
|
Name: "F100",
|
|
|
|
DeviceIDs: []string{"fpga1"},
|
|
|
|
})},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
|
|
|
nodeCapacity: defaultNodeResources,
|
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 512,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Devices: []*structs.RequestedDevice{
|
|
|
|
{
|
|
|
|
Name: "gpu",
|
|
|
|
Count: 6,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-09-21 21:05:00 +00:00
|
|
|
// This test case exercises the code path for a final filtering step that tries to
|
|
|
|
// minimize the number of preemptible allocations
|
|
|
|
{
|
|
|
|
desc: "Filter out allocs whose resource usage superset is also in the preemption list",
|
|
|
|
currentAllocations: []*structs.Allocation{
|
|
|
|
createAlloc(allocIDs[0], highPrioJob, &structs.Resources{
|
|
|
|
CPU: 1800,
|
|
|
|
MemoryMB: 2256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 150,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 1500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 5 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
createAlloc(allocIDs[2], lowPrioJob, &structs.Resources{
|
|
|
|
CPU: 600,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 5 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.200",
|
|
|
|
MBits: 300,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
nodeReservedCapacity: reservedNodeResources,
|
2018-11-02 14:09:50 +00:00
|
|
|
nodeCapacity: defaultNodeResources,
|
2018-09-21 21:05:00 +00:00
|
|
|
jobPriority: 100,
|
|
|
|
resourceAsk: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 5 * 1024,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
MBits: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preemptedAllocIDs: map[string]struct{}{
|
|
|
|
allocIDs[1]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
|
|
node := mock.Node()
|
2018-11-02 22:59:53 +00:00
|
|
|
node.NodeResources = tc.nodeCapacity
|
|
|
|
node.ReservedResources = tc.nodeReservedCapacity
|
2018-09-21 21:05:00 +00:00
|
|
|
|
|
|
|
state, ctx := testContext(t)
|
2019-04-11 01:20:22 +00:00
|
|
|
|
2018-09-21 21:05:00 +00:00
|
|
|
nodes := []*RankedNode{
|
|
|
|
{
|
|
|
|
Node: node,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
state.UpsertNode(1000, node)
|
|
|
|
for _, alloc := range tc.currentAllocations {
|
|
|
|
alloc.NodeID = node.ID
|
|
|
|
}
|
|
|
|
require := require.New(t)
|
|
|
|
err := state.UpsertAllocs(1001, tc.currentAllocations)
|
2018-10-17 01:46:44 +00:00
|
|
|
|
2018-09-21 21:05:00 +00:00
|
|
|
require.Nil(err)
|
|
|
|
if tc.currentPreemptions != nil {
|
|
|
|
ctx.plan.NodePreemptions[node.ID] = tc.currentPreemptions
|
|
|
|
}
|
|
|
|
static := NewStaticRankIterator(ctx, nodes)
|
2020-04-24 14:47:43 +00:00
|
|
|
binPackIter := NewBinPackIterator(ctx, static, true, tc.jobPriority, structs.SchedulerAlgorithmBinpack)
|
2019-04-11 01:20:22 +00:00
|
|
|
job := mock.Job()
|
|
|
|
job.Priority = tc.jobPriority
|
|
|
|
binPackIter.SetJob(job)
|
2018-09-21 21:05:00 +00:00
|
|
|
|
|
|
|
taskGroup := &structs.TaskGroup{
|
|
|
|
EphemeralDisk: &structs.EphemeralDisk{},
|
|
|
|
Tasks: []*structs.Task{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Resources: tc.resourceAsk,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-10-16 23:23:21 +00:00
|
|
|
|
2018-09-21 21:05:00 +00:00
|
|
|
binPackIter.SetTaskGroup(taskGroup)
|
|
|
|
option := binPackIter.Next()
|
|
|
|
if tc.preemptedAllocIDs == nil {
|
|
|
|
require.Nil(option)
|
|
|
|
} else {
|
|
|
|
require.NotNil(option)
|
|
|
|
preemptedAllocs := option.PreemptedAllocs
|
|
|
|
require.Equal(len(tc.preemptedAllocIDs), len(preemptedAllocs))
|
|
|
|
for _, alloc := range preemptedAllocs {
|
|
|
|
_, ok := tc.preemptedAllocIDs[alloc.ID]
|
2019-06-07 22:55:02 +00:00
|
|
|
require.Truef(ok, "alloc %s was preempted unexpectedly", alloc.ID)
|
2018-09-21 21:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper method to create allocations with given jobs and resources
|
|
|
|
func createAlloc(id string, job *structs.Job, resource *structs.Resources) *structs.Allocation {
|
2019-07-03 18:29:47 +00:00
|
|
|
return createAllocInner(id, job, resource, nil, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper method to create allocation with network at the task group level
|
|
|
|
func createAllocWithTaskgroupNetwork(id string, job *structs.Job, resource *structs.Resources, tgNet *structs.NetworkResource) *structs.Allocation {
|
|
|
|
return createAllocInner(id, job, resource, nil, tgNet)
|
2018-11-15 03:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func createAllocWithDevice(id string, job *structs.Job, resource *structs.Resources, allocatedDevices *structs.AllocatedDeviceResource) *structs.Allocation {
|
2019-07-03 18:29:47 +00:00
|
|
|
return createAllocInner(id, job, resource, allocatedDevices, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createAllocInner(id string, job *structs.Job, resource *structs.Resources, allocatedDevices *structs.AllocatedDeviceResource, tgNetwork *structs.NetworkResource) *structs.Allocation {
|
2018-09-21 21:05:00 +00:00
|
|
|
alloc := &structs.Allocation{
|
|
|
|
ID: id,
|
|
|
|
Job: job,
|
|
|
|
JobID: job.ID,
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
|
|
|
"web": resource,
|
|
|
|
},
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusRunning,
|
|
|
|
TaskGroup: "web",
|
2018-11-15 03:23:38 +00:00
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
2018-11-15 18:27:32 +00:00
|
|
|
"web": {
|
2018-11-15 03:23:38 +00:00
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: int64(resource.CPU),
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: int64(resource.MemoryMB),
|
|
|
|
},
|
|
|
|
Networks: resource.Networks,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if allocatedDevices != nil {
|
|
|
|
alloc.AllocatedResources.Tasks["web"].Devices = []*structs.AllocatedDeviceResource{allocatedDevices}
|
2018-09-21 21:05:00 +00:00
|
|
|
}
|
2019-07-03 18:29:47 +00:00
|
|
|
|
|
|
|
if tgNetwork != nil {
|
|
|
|
alloc.AllocatedResources.Shared = structs.AllocatedSharedResources{
|
|
|
|
Networks: []*structs.NetworkResource{tgNetwork},
|
|
|
|
}
|
|
|
|
}
|
2018-09-21 21:05:00 +00:00
|
|
|
return alloc
|
|
|
|
}
|