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

Render managed centrals in parallel #1434

Merged
merged 3 commits into from
Nov 3, 2023
Merged

Render managed centrals in parallel #1434

merged 3 commits into from
Nov 3, 2023

Conversation

ludydoo
Copy link
Collaborator

@ludydoo ludydoo commented Nov 3, 2023

No description provided.

index := i
g.Go(func() error {
var err error
managedDinosaurList.Items[index], err = h.presenter.PresentManagedCentral(centralRequests[index])
Copy link
Member

Choose a reason for hiding this comment

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

I see multiple challenges with this approach:

1. Race conditions:

This could lead to a race condition when to goroutines try to allocate the same address at the same time. The index is AFAIK not guaranteed to allocated the memory in an order.

You can still do this in two different ways:

  • We now the sice of the slice ahead of time, allocating the memory in the make state should do the trick to address the indexes according to their address
  • My favorite is using a channel, send the results to a channel and iterate over it, every result is appended to the result slice. This prevents shared memory access.

2. Excessive go routine creation
A limit is necessary for go routines to not create an unlimited amount of them.

3. Go routine stacking and cancellation:
When a go routine is blocked it is never cancelled or timed out. Fleetshard-Sync will timeout and continuously try to get Centrals. An additional call to GetAll triggers again a Go routine for every active Central.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This could lead to a race condition when to goroutines try to allocate the same address at the same time. The index is AFAIK not guaranteed to allocated the memory in an order.

I don't think that's true, the index is declared within the loop. It will only be scoped to the goroutine.

We now the sice of the slice ahead of time, allocating the memory in the make state should do the trick to address the indexes according to their address

That's already the case:

managedDinosaurList.Items = make([]private.ManagedCentral, len(centralRequests))

Go routine stacking and cancellation:

If the context is canceled, the errgroup will stop

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 added a max parallelism of 50

Copy link
Member

@SimonBaeumer SimonBaeumer Nov 3, 2023

Choose a reason for hiding this comment

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

I don't think that's true, the index is declared within the loop. It will only be scoped to the goroutine.

The memory allocation in the slice is not bound to the index. But this would only apply if you hadn't allocated the memory beforehand, I've not seen that 👍

If the context is canceled, the errgroup will stop

Uh, interesting I did not know that. TIL 🥳

index := i
g.Go(func() error {
var err error
managedDinosaurList.Items[index], err = h.presenter.PresentManagedCentral(centralRequests[index])
Copy link
Member

@SimonBaeumer SimonBaeumer Nov 3, 2023

Choose a reason for hiding this comment

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

I don't think that's true, the index is declared within the loop. It will only be scoped to the goroutine.

The memory allocation in the slice is not bound to the index. But this would only apply if you hadn't allocated the memory beforehand, I've not seen that 👍

If the context is canceled, the errgroup will stop

Uh, interesting I did not know that. TIL 🥳

Copy link
Contributor

openshift-ci bot commented Nov 3, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ludydoo, SimonBaeumer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [SimonBaeumer,ludydoo]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ludydoo ludydoo merged commit 290d813 into main Nov 3, 2023
8 checks passed
@ludydoo ludydoo deleted the render-centrals-parallel branch November 3, 2023 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants