Skip to content

Commit

Permalink
[release-1.16] Schduler: MAXFILLUP strategy will spread vreplicas acr…
Browse files Browse the repository at this point in the history
…oss multiple pods (#8291)

* Schduler: MAXFILLUP strategy will spread vreplicas across multiple pods

the MAXFILLUP algorithm was using an affinity strategy, meaning that
it would prioritize adding new vreplicas to pods with the same resources.

However, the downside is that if one pod goes down or gets
re-scheduled the entire resource would be down and not produce
events. By spreading replicas across multiple real replicas we would
guarantee better availability.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Remove configurable HA scheduler, fix reserved replicas logic

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Log reserved

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Handle unschedulables pods and always start from reserved no matter what is placements

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Add reserved + overcommit

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Add benchmark + reduce OrdinalFromPodName calls

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Handle unschedulable pods

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

---------

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
Co-authored-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
knative-prow-robot and pierDipi authored Oct 30, 2024
1 parent 291c0a8 commit 6db9011
Show file tree
Hide file tree
Showing 37 changed files with 865 additions and 5,904 deletions.
253 changes: 50 additions & 203 deletions pkg/scheduler/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/scheduler/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// The scheduler is responsible for placing virtual pod (VPod) replicas within real pods.
// Package scheduler is responsible for placing virtual pod (VPod) replicas within real pods.
package scheduler
88 changes: 0 additions & 88 deletions pkg/scheduler/factory/registry.go

This file was deleted.

22 changes: 0 additions & 22 deletions pkg/scheduler/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package scheduler

import (
"k8s.io/apimachinery/pkg/util/sets"
duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1"
)

Expand All @@ -29,24 +28,3 @@ func GetTotalVReplicas(placements []duckv1alpha1.Placement) int32 {
}
return r
}

// GetPlacementForPod returns the placement corresponding to podName
func GetPlacementForPod(placements []duckv1alpha1.Placement, podName string) *duckv1alpha1.Placement {
for i := 0; i < len(placements); i++ {
if placements[i].PodName == podName {
return &placements[i]
}
}
return nil
}

// GetPodCount returns the number of pods with the given placements
func GetPodCount(placements []duckv1alpha1.Placement) int {
set := sets.NewString()
for _, p := range placements {
if p.VReplicas > 0 {
set.Insert(p.PodName)
}
}
return set.Len()
}
92 changes: 0 additions & 92 deletions pkg/scheduler/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,95 +62,3 @@ func TestGetTotalVReplicas(t *testing.T) {
})
}
}

func TestGetPlacementForPod(t *testing.T) {
ps1 := []duckv1alpha1.Placement{{PodName: "p", VReplicas: 2}}
ps2 := []duckv1alpha1.Placement{{PodName: "p", VReplicas: 2}, {PodName: "p2", VReplicas: 4}}
testCases := []struct {
name string
podName string
placements []duckv1alpha1.Placement
expected *duckv1alpha1.Placement
}{
{
name: "nil placements",
podName: "p",
placements: nil,
expected: nil,
},
{
name: "empty placements",
podName: "p",
placements: []duckv1alpha1.Placement{},
expected: nil,
},
{
name: "one placement",
placements: ps1,
podName: "p",
expected: &ps1[0],
}, {
name: "mayne placements",
placements: ps2,
podName: "p2",
expected: &ps2[1],
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := GetPlacementForPod(tc.placements, tc.podName)
if got != tc.expected {
t.Errorf("got %v, want %v", got, tc.expected)
}
})
}
}
func TestPodCount(t *testing.T) {
testCases := []struct {
name string
placements []duckv1alpha1.Placement
expected int
}{
{
name: "nil placements",
placements: nil,
expected: 0,
},
{
name: "empty placements",
placements: []duckv1alpha1.Placement{},
expected: 0,
},
{
name: "one pod",
placements: []duckv1alpha1.Placement{{PodName: "d", VReplicas: 2}},
expected: 1,
},
{
name: "two pods",
placements: []duckv1alpha1.Placement{
{PodName: "p1", VReplicas: 2},
{PodName: "p2", VReplicas: 6},
{PodName: "p1", VReplicas: 6}},
expected: 2,
},
{
name: "three pods, one with no vreplicas",
placements: []duckv1alpha1.Placement{
{PodName: "p1", VReplicas: 2},
{PodName: "p2", VReplicas: 6},
{PodName: "p1", VReplicas: 0}},
expected: 2,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := GetPodCount(tc.placements)
if got != tc.expected {
t.Errorf("got %v, want %v", got, tc.expected)
}
})
}
}

This file was deleted.

Loading

0 comments on commit 6db9011

Please sign in to comment.