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

[Execution] Randomize collection fetch order #3445

Merged
merged 2 commits into from
Nov 10, 2022
Merged

Conversation

SaveTheRbtz
Copy link
Contributor

@SaveTheRbtz SaveTheRbtz commented Oct 25, 2022

Map iteration order is not random, but instead undefined (as per go spec):

The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next.

This does not mean random and especially not uniformly random. Therefore pre-randomize the order.

@SaveTheRbtz SaveTheRbtz force-pushed the rbtz/randomizeRequestOrder branch 2 times, most recently from 93a7510 to d15f56b Compare October 25, 2022 03:49
@SaveTheRbtz SaveTheRbtz marked this pull request as ready for review November 6, 2022 22:01
@bluesign
Copy link
Contributor

bluesign commented Nov 7, 2022

Why do we need uniform random here?

@SaveTheRbtz
Copy link
Contributor Author

Why do we need uniform random here?

The main reason for this randomness is to prevent the case scenario when we constantly request the same items over and over again because of the max batch size limit.

@bluesign
Copy link
Contributor

bluesign commented Nov 7, 2022

Why do we need uniform random here?

The main reason for this randomness is to prevent the case scenario when we constantly request the same items over and over again because of the max batch size limit.

I thought about that but doesn't

cutoff := item.LastRequested.Add(item.RetryAfter)
prevent that ?

Sorry maybe asking too much (trying to grasp flow-go lately) but also why aborting here?

return false, fmt.Errorf("no valid providers available")
Instead of moving to the next item ?

engine/common/requester/engine.go Outdated Show resolved Hide resolved
@SaveTheRbtz
Copy link
Contributor Author

Why do we need uniform random here?

The main reason for this randomness is to prevent the case scenario when we constantly request the same items over and over again because of the max batch size limit.

I thought about that but doesn't

cutoff := item.LastRequested.Add(item.RetryAfter)

prevent that ?

it would help sometimes depending on the phase of moon (timeouts, error rates, frequency of calling this function, etc.). It is better to explicitly randomize the order though.

Sorry maybe asking too much (trying to grasp flow-go lately) but also why aborting here?

return false, fmt.Errorf("no valid providers available")

Instead of moving to the next item ?

It's a good question. The answer to it is: it was simpler: the complexity of this function is already too high. In reality we just need to refactor that piece of code to reduce complexity.

@SaveTheRbtz
Copy link
Contributor Author

bors merge

@bors bors bot merged commit d48a662 into master Nov 10, 2022
@bors bors bot deleted the rbtz/randomizeRequestOrder branch November 10, 2022 09:16
This pull request was closed.
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.

4 participants