-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Regression] Fleet scale down didn't adhere to Packed Scheduling
The new Fleet scale up/scale down performance enhancements removed the functionality that the `Packed` strategy is documented to provide -- when scaling down, removing GameServers from least used Nodes first. This change implements a library for GameServer sorting that doesn't use reflection, unlike sort.Slice (much faster), and can be used with any Comparator, as I expect we'll likely need this again. This also pulls out the GameServerCounter controller - which keeps a running total of GameServers per Node, to make this kind of sorting much faster and easier as we don't have to compute this on every iteration. To maintain performance as well, the set of GameServers only get sorted when scaling down, and only for Packed strategy.
- Loading branch information
1 parent
0b9af68
commit 406f1b6
Showing
13 changed files
with
263 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2019 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1alpha1 | ||
|
||
import "sort" | ||
|
||
// GameServerSort sorts gameservers, based on a comparator | ||
type GameServerSort struct { | ||
// List is the GameServer list to sort | ||
List []*GameServer | ||
// Less is the comparator function to use as a sorting function. | ||
// returns true if a < b | ||
Comparator func(a, b *GameServer) bool | ||
} | ||
|
||
// Sort sorts the underlying Array and returns it | ||
func (g *GameServerSort) Sort() []*GameServer { | ||
sort.Sort(g) | ||
return g.List | ||
} | ||
|
||
// Len is the Len function for sort.Interface | ||
func (g *GameServerSort) Len() int { | ||
return len(g.List) | ||
} | ||
|
||
// Less is the Less function for sort.Interface | ||
func (g *GameServerSort) Less(i, j int) bool { | ||
a := g.List[i] | ||
b := g.List[j] | ||
|
||
return g.Comparator(a, b) | ||
} | ||
|
||
// Swap is the swap function for sort.Interface | ||
func (g *GameServerSort) Swap(i, j int) { | ||
tmp := g.List[j] | ||
g.List[j] = g.List[i] | ||
g.List[i] = tmp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2019 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestGameServerSortSort(t *testing.T) { | ||
list := []*GameServer{{ObjectMeta: metav1.ObjectMeta{Name: "c"}}, | ||
{ObjectMeta: metav1.ObjectMeta{Name: "b"}}, {ObjectMeta: metav1.ObjectMeta{Name: "a"}}} | ||
|
||
sort := GameServerSort{list, func(a, b *GameServer) bool { | ||
return a.ObjectMeta.Name < b.ObjectMeta.Name | ||
}} | ||
|
||
result := sort.Sort() | ||
assert.Len(t, result, len(list)) | ||
assert.Equal(t, "a", result[0].ObjectMeta.Name) | ||
assert.Equal(t, "b", result[1].ObjectMeta.Name) | ||
assert.Equal(t, "c", result[2].ObjectMeta.Name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.