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

Create a goroutine worker pool to send data from distributors to ingesters. #6406

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

alanprot
Copy link
Member

@alanprot alanprot commented Dec 7, 2024

What this PR does:
Implement an option to use a goroutine worker pool to handle requests from the distributor to ingesters, rather than spawning a new goroutine for each request.

This PR was inspired on: grpc/grpc-go#3204

Looking at the distributor flame graph, we could see that lots of cpu was being used on the runtime.newstack call:
Screenshot 2024-12-06 at 4 11 37 PM

This problem increases with the RemoteWrite TPS and the number of ingesters in the cluster (as, for request and ingesters, we create a new go routine).

With this PR enabled, we could see a reduction on 20% of CPU on some cortex cluster with hundreds of ingesters.

Screenshot 2024-12-06 at 4 21 22 PM

We could not see any runtime.newstack on the cpu flamegraph after the option was enabled.

Screenshot 2024-12-06 at 4 15 11 PM

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Comment on lines 126 to +131
for _, i := range instances {
go func(i instance) {
e.Submit(func() {
err := callback(i.desc, i.indexes)
tracker.record(i, err)
wg.Done()
}(i)
})
Copy link
Member Author

Choose a reason for hiding this comment

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

The closure var should be fine now:

https://tip.golang.org/doc/go1.22

Previously, the variables declared by a “for” loop were created once and updated by each iteration. In Go 1.22, each iteration of the loop creates new variables, to avoid accidental sharing bugs. The transition support tooling described in the proposal continues to work in the same way it did in Go 1.21.

@alanprot alanprot force-pushed the distributor-worker-pool branch from bb63874 to 2a0e956 Compare December 7, 2024 00:20
@alanprot alanprot marked this pull request as ready for review December 7, 2024 00:22
@alanprot alanprot force-pushed the distributor-worker-pool branch 2 times, most recently from ea066bd to 3c5ff63 Compare December 7, 2024 00:35
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

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

Great work.
Is it worth a changelog? And experimental feature?

@alanprot alanprot force-pushed the distributor-worker-pool branch from 3c5ff63 to 4bbfa0c Compare December 10, 2024 00:22
@alanprot
Copy link
Member Author

Great work. Is it worth a changelog? And experimental feature?

I forgot about changelog. :P

Yeah.. lemme mark as experimental.

Signed-off-by: alanprot <[email protected]>
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 10, 2024
@alanprot alanprot merged commit 5d2dac0 into cortexproject:master Dec 10, 2024
16 checks passed
@alanprot alanprot deleted the distributor-worker-pool branch December 10, 2024 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/distributor lgtm This PR has been approved by a maintainer size/L type/performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants