-
Notifications
You must be signed in to change notification settings - Fork 649
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
bench: aggregate adding completed ops for reads #721
bench: aggregate adding completed ops for reads #721
Conversation
cmd/bbolt/main.go
Outdated
@@ -1380,10 +1380,10 @@ func (cmd *benchCommand) runReadsSequential(db *bolt.DB, options *BenchOptions, | |||
|
|||
for { | |||
numReads := int64(0) | |||
defer func() { results.AddCompletedOps(numReads) }() |
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.
I debated using a defer or manually adding the call at the end of the loop. I ended up doing it with the defer, as there are some cases in which it would need to be called from inside the if condition if the run had an error and outside, too. So, it feels cleaner. However, I'm unsure if too many defers (one per loop) would create issues with the call stack if there are too many iterations.
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.
Adding defer
inside a for loop isn't a good practice.
How about this?
err := func() error {
defer func() { results.AddCompletedOps(numReads) }()
c := tx.Bucket(benchBucketName).Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
numReads++
if v == nil {
return ErrInvalidValue
}
}
return nil
}()
if err != nil {
return err
}
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.
Note that deferred function won't be called until the surrounding function returns. It means the initial motivation of progress notification is broken. My proposed change above can fix it.
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.
@ahrtr, I applied the suggestion. PTAL :)
/lgtm |
Also we can also do similar enhancement in |
Hey @ahrtr, unfortunately (as I mentioned in #720 (comment)), changing the |
@ivanvc Please resolve the comment, also read #720 (comment) |
Sorry, @ahrtr, for some reason, I missed the notification and didn't read your comment. I'll address it later today. |
Currently, the completed operations are added to the read benchmarks one by one, and given that each operation is atomic, it impacts the benchmark's performance. Change to update only once per cycle, with the total number of reads. Signed-off-by: Ivan Valdes <ivan@vald.es>
0e36040
to
43c669d
Compare
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.
LGTM
Currently, the completed operations are added to the read benchmarks one by one, and given that each operation is atomic, it impacts the benchmark's performance. Change to update only once per cycle, with the total number of reads.
Related to #720