Skip to content

Commit 8546661

Browse files
authored
Removal of getRandomlySelectedGS (agones-dev#2144)
When refactoring the allocator code for agones-dev#2143 I noticed that this function was never actually utilised for anything, so figured it made sense to remove it.
1 parent b115471 commit 8546661

2 files changed

Lines changed: 0 additions & 62 deletions

File tree

‎pkg/gameserverallocations/allocator.go‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ import (
1919
"crypto/tls"
2020
"crypto/x509"
2121
"fmt"
22-
"math/rand"
2322
"net/http"
24-
"strconv"
2523
"strings"
2624
"time"
2725

@@ -73,11 +71,6 @@ const (
7371
secretClientKeyName = "tls.key"
7472
secretCACertName = "ca.crt"
7573
allocatorPort = "443"
76-
77-
// Instead of selecting the top one, controller selects a random one
78-
// from the topNGameServerCount of Ready gameservers
79-
// to reduce the contention while allocating gameservers.
80-
topNGameServerDefaultCount = 100
8174
)
8275

8376
const (
@@ -109,7 +102,6 @@ type Allocator struct {
109102
recorder record.EventRecorder
110103
pendingRequests chan request
111104
readyGameServerCache *ReadyGameServerCache
112-
topNGameServerCount int
113105
remoteAllocationCallback func(context.Context, string, grpc.DialOption, *pb.AllocationRequest) (*pb.AllocationResponse, error)
114106
remoteAllocationTimeout time.Duration
115107
totalRemoteAllocationTimeout time.Duration
@@ -138,7 +130,6 @@ func NewAllocator(policyInformer multiclusterinformerv1.GameServerAllocationPoli
138130
secretLister: secretInformer.Lister(),
139131
secretSynced: secretInformer.Informer().HasSynced,
140132
readyGameServerCache: readyGameServerCache,
141-
topNGameServerCount: topNGameServerDefaultCount,
142133
remoteAllocationTimeout: remoteAllocationTimeout,
143134
totalRemoteAllocationTimeout: totalRemoteAllocationTimeout,
144135
remoteAllocationCallback: func(ctx context.Context, endpoint string, dialOpts grpc.DialOption, request *pb.AllocationRequest) (*pb.AllocationResponse, error) {
@@ -607,24 +598,6 @@ func Retry(backoff wait.Backoff, fn func() error) error {
607598
return err
608599
}
609600

610-
// getRandomlySelectedGS selects a GS from the set of Gameservers randomly. This will reduce the contentions
611-
func (c *Allocator) getRandomlySelectedGS(gsa *allocationv1.GameServerAllocation, bestGSList []agonesv1.GameServer) *agonesv1.GameServer {
612-
seed, err := strconv.Atoi(gsa.ObjectMeta.ResourceVersion)
613-
if err != nil {
614-
seed = 1234567
615-
}
616-
617-
ln := c.topNGameServerCount
618-
if ln > len(bestGSList) {
619-
ln = len(bestGSList)
620-
}
621-
622-
startIndex := len(bestGSList) - ln
623-
bestGSList = bestGSList[startIndex:]
624-
index := rand.New(rand.NewSource(int64(seed))).Intn(ln)
625-
return &bestGSList[index]
626-
}
627-
628601
// newMetrics creates a new gsa latency recorder.
629602
func (c *Allocator) newMetrics(ctx context.Context) *metrics {
630603
ctx, err := tag.New(ctx, latencyTags...)

‎pkg/gameserverallocations/controller_test.go‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -561,40 +561,6 @@ func TestControllerRunCacheSync(t *testing.T) {
561561
assertCacheEntries(0)
562562
}
563563

564-
func TestGetRandomlySelectedGS(t *testing.T) {
565-
c, _ := newFakeController()
566-
c.allocator.topNGameServerCount = 5
567-
gsa := &allocationv1.GameServerAllocation{
568-
ObjectMeta: metav1.ObjectMeta{
569-
Namespace: defaultNs,
570-
Name: "allocation",
571-
},
572-
Status: allocationv1.GameServerAllocationStatus{
573-
State: allocationv1.GameServerAllocationUnAllocated,
574-
},
575-
}
576-
577-
_, gsList := defaultFixtures(10)
578-
579-
selectedGS := c.allocator.getRandomlySelectedGS(gsa, gsList)
580-
assert.NotNil(t, "selectedGS can't be nil", selectedGS)
581-
for i := 1; i <= 5; i++ {
582-
expectedName := "gs" + strconv.Itoa(i)
583-
assert.NotEqual(t, expectedName, selectedGS.ObjectMeta.Name)
584-
}
585-
586-
_, gsList = defaultFixtures(5)
587-
588-
selectedGS = c.allocator.getRandomlySelectedGS(gsa, gsList)
589-
assert.NotNil(t, "selectedGS can't be nil", selectedGS)
590-
591-
_, gsList = defaultFixtures(1)
592-
593-
selectedGS = c.allocator.getRandomlySelectedGS(gsa, gsList)
594-
assert.NotNil(t, "selectedGS can't be nil", selectedGS)
595-
assert.Equal(t, "gs1", selectedGS.ObjectMeta.Name)
596-
}
597-
598564
func TestControllerAllocationUpdateWorkers(t *testing.T) {
599565
t.Run("no error", func(t *testing.T) {
600566
c, m := newFakeController()
@@ -1553,7 +1519,6 @@ func newFakeControllerWithTimeout(remoteAllocationTimeout time.Duration, totalRe
15531519
counter := gameservers.NewPerNodeCounter(m.KubeInformerFactory, m.AgonesInformerFactory)
15541520
api := apiserver.NewAPIServer(m.Mux)
15551521
c := NewController(api, healthcheck.NewHandler(), counter, m.KubeClient, m.KubeInformerFactory, m.AgonesClient, m.AgonesInformerFactory, remoteAllocationTimeout, totalRemoteAllocationTimeout)
1556-
c.allocator.topNGameServerCount = 1
15571522
c.recorder = m.FakeRecorder
15581523
c.allocator.recorder = m.FakeRecorder
15591524
return c, m

0 commit comments

Comments
 (0)