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

feat: add leaseCache to change gc policy #172

Merged
merged 4 commits into from
Aug 21, 2023
Merged

Conversation

Desiki-high
Copy link
Collaborator

@Desiki-high Desiki-high commented Aug 15, 2023

Change GC policy

This patch changes GC policy from LRU to LFU/LRU: cleans the blob by LFU first then LRU.

Change:

  • add singleflight for gc.
  • add leaseCache: the cache of lease, help record the used count and time.
  • implement the new policy of GC by leaseCache.
  • update lease in commit. To make leaseCache is synchronized with local storage before read each blob.

⚠️Notice:
The leaseCache is not thread-safe, we make sure the safe by the gcSingleflight and the thread-safe of content.db.Update.

Ref: #141

Test result of leaseCache:

  • TestLeaseCache 0.007s Add(5) Remove(3)
  • TestLeaseCacheInit 0.016s Add(6) Remove(1) Init(1) Add (5)

@Desiki-high Desiki-high force-pushed the feat-lrfu branch 4 times, most recently from 6ebfa68 to 71e1747 Compare August 15, 2023 11:55
pkg/content/content.go Outdated Show resolved Hide resolved
pkg/content/content.go Outdated Show resolved Hide resolved
pkg/content/cache_test.go Show resolved Hide resolved
Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
LeaseCache will cache the used count and last used order of each blob.
Gc can clean the lease by leaseCache.

Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
pkg/content/cache_test.go Outdated Show resolved Hide resolved
Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
To make leaseCache is synchronized with local storage before read each blob.

Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
@imeoer imeoer merged commit 1d72948 into goharbor:main Aug 21, 2023
6 checks passed
@imeoer imeoer mentioned this pull request Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants