1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 var _ = Suite(&PrioritySuite{})
13 type PrioritySuite struct{}
15 func (s *PrioritySuite) TestReniceCorrect(c *C) {
16 for _, test := range []struct {
33 []*slurmJob{{priority: 4294000111, nice: 10000}},
39 {priority: 4294000111, nice: 10000},
40 {priority: 4294000111, nice: 10000},
41 {priority: 4294000111, nice: 10000},
42 {priority: 4294000111, nice: 10000},
44 []int64{0, 10, 20, 30},
46 { // smaller spread than necessary, but correctly ordered => leave nice alone
49 {priority: 4294000113, nice: 0},
50 {priority: 4294000112, nice: 1},
51 {priority: 4294000111, nice: 99},
55 { // larger spread than necessary, but less than 10x => leave nice alone
58 {priority: 4294000144, nice: 0},
59 {priority: 4294000122, nice: 20},
60 {priority: 4294000111, nice: 30},
64 { // > 10x spread => reduce nice to achieve spread=10
67 {priority: 4000, nice: 0}, // max pri 4000
68 {priority: 3000, nice: 999}, // max pri 3999
69 {priority: 2000, nice: 1998}, // max pri 3998
73 { // > 10x spread, but spread=10 is impossible without negative nice
76 {priority: 4000, nice: 0}, // max pri 4000
77 {priority: 3000, nice: 500}, // max pri 3500
78 {priority: 2000, nice: 2000}, // max pri 4000
82 { // default spread, needs reorder
85 {priority: 4000, nice: 0}, // max pri 4000
86 {priority: 5000, nice: 0}, // max pri 5000
87 {priority: 6000, nice: 0}, // max pri 6000
89 []int64{0, 1000 + defaultSpread, 2000 + defaultSpread*2},
94 {priority: 4000, nice: 0}, // max pri 4000
95 {priority: 5000, nice: 0}, // max pri 5000
96 {priority: 6000, nice: 0}, // max pri 6000
97 {priority: 3000, nice: 0}, // max pri 3000
99 []int64{0, 1001, 2002, 0},
102 c.Logf("spread=%d %+v -> %+v", test.spread, test.in, test.out)
103 c.Check(wantNice(test.in, test.spread), DeepEquals, test.out)
105 if len(test.in) == 0 {
108 // After making the adjustments, calling wantNice
109 // again should return the same recommendations.
110 updated := make([]*slurmJob, len(test.in))
111 for i, in := range test.in {
112 updated[i] = &slurmJob{
114 priority: in.priority + in.nice - test.out[i],
117 c.Check(wantNice(updated, test.spread), DeepEquals, test.out)
121 func (s *PrioritySuite) TestReniceChurn(c *C) {
123 jobs := make([]*slurmJob, 1000)
124 for i := range jobs {
125 jobs[i] = &slurmJob{priority: 4294000000 - int64(i), nice: 10000}
130 renice := wantNice(queue, spread)
131 for i := range queue {
132 if renice[i] == queue[i].nice {
135 queue[i].priority += queue[i].nice - renice[i]
136 queue[i].nice = renice[i]
141 c.Logf("processed queue of %d with %d renice ops", len(jobs), adjustments)
142 c.Check(adjustments < len(jobs)*len(jobs)/10, Equals, true)