Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a worker pool to add concurrency limit on gif renders #35

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

robbles
Copy link
Contributor

@robbles robbles commented Dec 13, 2023

This uses https://github.com/alitto/pond to add a middleware that wraps all gif rendering endpoints with a worker pool that limits concurrent executions to the number of CPUs, and allows up to 40 requests to sit in a queue until a worker frees up. After that limit is reached, requests with get a HTTP 429 instead to avoid hitting the overall Cloud Run active request limit.

This isn't exactly heavily tested, but I have poked at it locally a fair bit with lower numbers for the pool, and it seems to work as expected...? The worst case I'd expect is that this causes a memory leak if I got something wrong. I don't think it'll crash exporter, so it'll probably be a net improvement over intermittently denying all requests.

I also got a warning from running go mod tidy after adding the new dependency. It seems to happen on main as well, so I don't think I introduced it, but if I chose the wrong thing it might be making unnecessary changes to the deps:

github.com/BattlesnakeOfficial/exporter/http imports
	github.com/sirupsen/logrus imports
	golang.org/x/sys/unix loaded from golang.org/x/[email protected],
	but go 1.16 would select v0.5.0
github.com/BattlesnakeOfficial/exporter/http imports
	github.com/sirupsen/logrus imports
	golang.org/x/sys/windows loaded from golang.org/x/[email protected],
	but go 1.16 would select v0.5.0
github.com/BattlesnakeOfficial/exporter/http imports
	github.com/sirupsen/logrus imports
	golang.org/x/sys/unix imports
	golang.org/x/sys/internal/unsafeheader loaded from golang.org/x/[email protected],
	but go 1.16 would select v0.5.0

To upgrade to the versions selected by go 1.16:
	go mod tidy -go=1.16 && go mod tidy -go=1.17
If reproducibility with go 1.16 is not needed:
	go mod tidy -compat=1.17
For other options, see:
	https://golang.org/doc/modules/pruning

@robbles robbles requested a review from bvanvugt as a code owner December 13, 2023 05:36
@bvanvugt bvanvugt merged commit 77b6677 into main Dec 13, 2023
8 checks passed
@bvanvugt bvanvugt deleted the gif_concurrency_limit branch December 13, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants