-
Notifications
You must be signed in to change notification settings - Fork 338
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
perf: improve eviction worker cpu use #4234
Conversation
// target might change. This is to prevent unreserve from running with | ||
// the old target. | ||
if !unreserveSem.TryAcquire(1) { | ||
cancelUnreserve() |
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.
instead of cancelling, would it make sense to wait for the unreserve to finish first with unreserveSem.Acquire
?
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.
So it could happen that the unreserve target is substantial. Which is why this cancellation was added to mainly prevent removing valid chunks till we need to.
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.
as long as canceling is safe (for example with things like returning correct eviction counts etc), im ok with this.
another small issue maybe this cancel func needs to be initially assigned a noOp func to prevent a panic
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.
return | ||
} | ||
expiryWorkers.Release(4) | ||
defer db.events.Trigger(reserveUnreserved) |
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.
why is this emitted?
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.
This was actually added for the test mainly. No one is listening for it. I thought its easier to use the same one than to have a separate key. Wdyt?
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.
right, works for me, maybe a small comment is needed.
}() | ||
} | ||
|
||
if err := expiryWorkers.Acquire(ctx, 4); err != nil { |
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.
what is the purpose of this?
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.
This is to ensure all expiry workers finished before we give up the sem. At the most, we will start 4 workers in parallel to expire. There are more workers here as for expired batches each of them will be working on different entries, so they can all do it in parallel.
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 see, we can have at most 4 removeExpiredBatch
funcs running in parallel. the Acquire
here waits for the above calls to finish.
Checklist
Description
Debugging on resource-constrained machines, we found some unnecessary goroutine creations and also excessive expiry checks. Thanks to @ldeffenb for helping out with this! These changes should improve the CPU consumption of the nodes.
Also, a bug was found with the move to cache where the reserve size was not being changed correctly. This is fixed by moving the cache op into the same transaction, so it can be reverted together.