Skip to content

Conversation

markmandel
Copy link
Collaborator

What type of PR is this?

Uncomment only one /kind <> line, press enter to put that in a new line, and remove leading whitespace from that line:

/kind breaking

/kind bug

/kind cleanup
/kind documentation
/kind feature
/kind hotfix
/kind release

What this PR does / Why we need it:

We want the allocated GameServer back in the cache anyway for re-allocation, so might as well get it back in as soon as possible.

Which issue(s) this PR fixes:

Work on #3992

Special notes for your reviewer:

@github-actions github-actions bot added the kind/bug These are bugs. label Apr 17, 2025
@agones-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: 800070be-37f3-4e69-b24f-15f108a1ac20

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

git fetch https://github.com/googleforgames/agones.git pull/4159/head:pr_4159 && git checkout pr_4159
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.49.0-dev-2ef2d5e

@markmandel markmandel changed the title Allocation: Re-cache allocated GameSerer Allocation: Re-cache allocated GameServer Apr 17, 2025
@markmandel markmandel added the area/performance Anything to do with Agones being slow, or making it go faster. label Apr 18, 2025
@igooch
Copy link
Collaborator

igooch commented Apr 21, 2025

@dmorgan-blizz FYI this is one proposal for your issue #3992. Let us know how this performs.

@markmandel
Copy link
Collaborator Author

@dmorgan-blizz FYI this is one proposal for your issue #3992. Let us know how this performs.

There should be no downside to this change, it should help no matter what.

@markmandel
Copy link
Collaborator Author

Any blocking reason this shouldn't be merged?

@agones-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: 2c277f71-ca90-4eb7-9ef5-a04a815ff008

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

git fetch https://github.com/googleforgames/agones.git pull/4159/head:pr_4159 && git checkout pr_4159
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.49.0-dev-d042a1d

Copy link
Collaborator

@peterzhongyi peterzhongyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we worry about the informer giving a stale update on the game server that overwrites the game server record you write here? Seems like it might happen frequently given that the informer is almost always going to be slower but will still try to write the the cache?

@markmandel
Copy link
Collaborator Author

🤔 I can't think of an example, since the Informer is only going to give you the latest version of the GameServer instance.

We could do a generation check on store, and if it's less than the latest version that is stored in there (which is possibly not a bad idea anyway), we reject it.

func (e *gameServerCache) Store(key string, gs *agonesv1.GameServer) {
e.mu.Lock()
defer e.mu.Unlock()
if e.cache == nil {
e.cache = map[string]*agonesv1.GameServer{}
}
e.cache[key] = gs.DeepCopy()

Actually, that's a pretty good idea anyway, I'll put that in 👍🏻 seems like thing that shouldn't happen often (ever?), but easy enough to make sure it doesn't.

We want the allocated `GameServer` back in the cache anyway for
re-allocation, so might as well get it back in as soon as possible.

Work on googleforgames#3992
@peterzhongyi
Copy link
Collaborator

Sounds good. LGTM!

@agones-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: 9a44c0be-ec98-48a9-9c04-0b3be35b39e6

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

git fetch https://github.com/googleforgames/agones.git pull/4159/head:pr_4159 && git checkout pr_4159
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.49.0-dev-c1199d6

if existingGS, ok := e.cache[key]; ok {
// If the incoming gs object's Generation is less than the existing one, ignore it, but also check the ResourceVersion
// saves us a deep copy if we don't need to
if gs.ObjectMeta.Generation < existingGS.ObjectMeta.Generation || gs.ObjectMeta.ResourceVersion == existingGS.ObjectMeta.ResourceVersion {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had forgotten that you can get resourceVersion change, but with no Generation change, so you have to account for it, and lean on eventual consistency when it's needed.

@agones-bot
Copy link
Collaborator

Build Failed 😭

Build Id: 7aebfd4a-d18d-4d04-9bd5-ebe1ec51fb2e

Status: FAILURE

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: f4d08f7b-4d6a-4cfd-bb5c-144be473a4a0

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

git fetch https://github.com/googleforgames/agones.git pull/4159/head:pr_4159 && git checkout pr_4159
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.49.0-dev-831a8e2

@markmandel markmandel merged commit 4b0c6c2 into googleforgames:main Apr 30, 2025
4 checks passed
@markmandel markmandel deleted the perf/re-allocation branch April 30, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/performance Anything to do with Agones being slow, or making it go faster. kind/bug These are bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants