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

merkledb -- limit number of goroutines calculating node IDs #1960

Merged
merged 13 commits into from
Sep 5, 2023

Conversation

danlaine
Copy link

@danlaine danlaine commented Sep 5, 2023

Why this should be merged

Resolves TODO. Alternate to #1957.

How this works

Uses a semaphore to control the number of goroutines calculating node IDs (namely the number of goroutines executing calculateNodeIDsHelper) across all views.

In calculateNodeIDs, we will block until we acquire from the semaphore before calling calculateNodeIDsHelper.
In calculateNodeIDsHelper, we call calculateNodeIDsHelper in a goroutine iff the semaphore has unused resources. Otherwise, we call calculateNodeIDsHelper recursively.

How this was tested

Existing UT

@danlaine danlaine added cleanup Code quality improvement merkledb labels Sep 5, 2023
@danlaine danlaine self-assigned this Sep 5, 2023
wg sync.WaitGroup
updatedChildren = make(chan *node, len(n.children))
)

for childIndex, child := range n.children {
childIndex, child := childIndex, child
Copy link
Author

Choose a reason for hiding this comment

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

Don't think this was actually necessary

if err = eg.Wait(); err != nil {
return
}
_ = t.db.calculateNodeIDsSema.Acquire(context.Background(), 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this to have the # of threads match the semaphore weight?

Copy link
Author

Choose a reason for hiding this comment

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

Not sure I understand the question. In order for a new goroutine to run calculateNodeIDsHelper, it must acquire 1 from the semaphore and release that 1 when it exits the goroutine.

Base automatically changed from merkledb-remove-unneeded-errors to dev September 5, 2023 17:21
x/merkledb/db.go Outdated Show resolved Hide resolved
@danlaine danlaine merged commit ecf6b4f into dev Sep 5, 2023
16 checks passed
@danlaine danlaine deleted the merkledb-limit-calculation-goroutines branch September 5, 2023 21:29
@danlaine danlaine added this to the v1.10.10 milestone Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement merkledb
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants