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

perf: improve eviction worker cpu use #4234

Merged
merged 3 commits into from
Jul 31, 2023
Merged

Conversation

aloknerurkar
Copy link
Contributor

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

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.

@aloknerurkar aloknerurkar changed the title Evict worker opt perf: improve eviction worker cpu use Jul 29, 2023
@aloknerurkar aloknerurkar marked this pull request as ready for review July 31, 2023 10:53
// target might change. This is to prevent unreserve from running with
// the old target.
if !unreserveSem.TryAcquire(1) {
cancelUnreserve()
Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Member

@istae istae Jul 31, 2023

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually tested. We even found that there was actually an issue with the counts. This is fixed in the next PR where we keep track of the counts per batch. That fix was tested with @ldeffenb s help, where the counts were verified after restarts.

return
}
expiryWorkers.Release(4)
defer db.events.Trigger(reserveUnreserved)
Copy link
Member

Choose a reason for hiding this comment

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

why is this emitted?

Copy link
Contributor Author

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?

Copy link
Member

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 {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@aloknerurkar aloknerurkar merged commit 2cfdedb into evict-cache Jul 31, 2023
9 of 12 checks passed
@aloknerurkar aloknerurkar deleted the evict-worker-opt branch July 31, 2023 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants