-
Notifications
You must be signed in to change notification settings - Fork 674
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
Conversation
wg sync.WaitGroup | ||
updatedChildren = make(chan *node, len(n.children)) | ||
) | ||
|
||
for childIndex, child := range n.children { | ||
childIndex, child := childIndex, child |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…a-labs/avalanchego into merkledb-limit-calculation-goroutines
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 callingcalculateNodeIDsHelper
.In
calculateNodeIDsHelper
, we callcalculateNodeIDsHelper
in a goroutine iff the semaphore has unused resources. Otherwise, we callcalculateNodeIDsHelper
recursively.How this was tested
Existing UT