Skip to content

Added BST for efficient deletion#27

Open
beppeben wants to merge 20 commits intopatrickmn:masterfrom
beppeben:master
Open

Added BST for efficient deletion#27
beppeben wants to merge 20 commits intopatrickmn:masterfrom
beppeben:master

Conversation

@beppeben
Copy link
Copy Markdown

@beppeben beppeben commented Dec 5, 2015

Added a BST to the cache data structure. Insertions of new elements, deletions, and expiration changes are slower operations now (O(logn) instead of O(1)). However the bulk removal of expired objects is faster when expired elements are not "too many".
Examining the tradeoff between these two effects may be a bit tricky. The benchmarks that I introduced seem to indicate that this new version performs better than the original one whenever the bulk deletions remove less than 1% of the of the elements.
Here are my results:

original:

BenchmarkCacheGetExpiring-4 20000000 74.5 ns/op
BenchmarkCacheGetNotExpiring-4 50000000 37.7 ns/op
BenchmarkRWMutexMapGet-4 50000000 30.5 ns/op
BenchmarkRWMutexInterfaceMapGetStruct-4 20000000 84.2 ns/op
BenchmarkRWMutexInterfaceMapGetString-4 20000000 82.9 ns/op
BenchmarkCacheGetConcurrentExpiring-4 20000000 72.9 ns/op
BenchmarkCacheGetConcurrentNotExpiring-4 20000000 62.7 ns/op
BenchmarkRWMutexMapGetConcurrent-4 30000000 54.4 ns/op
BenchmarkCacheGetManyConcurrentExpiring-4 2000000000 66.6 ns/op
BenchmarkCacheGetManyConcurrentNotExpiring-4 30000000 65.7 ns/op
BenchmarkCacheSetExpiring-4 10000000 237 ns/op
BenchmarkCacheSetNotExpiring-4 10000000 201 ns/op
BenchmarkRWMutexMapSet-4 20000000 89.4 ns/op
BenchmarkCacheSetDelete-4 5000000 301 ns/op
BenchmarkRWMutexMapSetDelete-4 10000000 179 ns/op
BenchmarkCacheSetDeleteSingleLock-4 5000000 266 ns/op
BenchmarkRWMutexMapSetDeleteSingleLock-4 10000000 140 ns/op
BenchmarkIncrementInt-4 10000000 209 ns/op
BenchmarkDeleteExpiredLoop-4 500 2892388 ns/op
BenchmarkLargeCache01-4 1000000 27441 ns/op
BenchmarkLargeCache02-4 1000000 35324 ns/op
BenchmarkLargeCache05-4 1000000 14706 ns/op
BenchmarkLargeCache10-4 1000000 8612 ns/op
BenchmarkLargeCache20-4 1000000 5408 ns/op
BenchmarkLargeCache50-4 1000000 2729 ns/op
BenchmarkShardedCacheGetExpiring-4 20000000 111 ns/op
BenchmarkShardedCacheGetNotExpiring-4 20000000 69.7 ns/op
BenchmarkShardedCacheGetManyConcurrentExpiring-4 20000000 76.0 ns/op
BenchmarkShardedCacheGetManyConcurrentNotExpiring-4 20000000 68.5 ns/op

new:

BenchmarkCacheGetExpiring-4 20000000 75.3 ns/op
BenchmarkCacheGetNotExpiring-4 50000000 37.9 ns/op
BenchmarkRWMutexMapGet-4 50000000 33.8 ns/op
BenchmarkRWMutexInterfaceMapGetStruct-4 20000000 81.5 ns/op
BenchmarkRWMutexInterfaceMapGetString-4 20000000 80.3 ns/op
BenchmarkCacheGetConcurrentExpiring-4 20000000 60.4 ns/op
BenchmarkCacheGetConcurrentNotExpiring-4 20000000 63.1 ns/op
BenchmarkRWMutexMapGetConcurrent-4 30000000 57.3 ns/op
BenchmarkCacheGetManyConcurrentExpiring-4 2000000000 61.8 ns/op
BenchmarkCacheGetManyConcurrentNotExpiring-4 30000000 64.4 ns/op
BenchmarkCacheSetExpiring-4 2000000 856 ns/op
BenchmarkCacheSetNotExpiring-4 10000000 199 ns/op
BenchmarkRWMutexMapSet-4 20000000 92.6 ns/op
BenchmarkCacheSetDelete-4 3000000 491 ns/op
BenchmarkRWMutexMapSetDelete-4 10000000 176 ns/op
BenchmarkCacheSetDeleteSingleLock-4 3000000 444 ns/op
BenchmarkRWMutexMapSetDeleteSingleLock-4 10000000 144 ns/op
BenchmarkIncrementInt-4 10000000 213 ns/op
BenchmarkDeleteExpiredLoop-4 1000000 1712 ns/op
BenchmarkLargeCache01-4 1000000 8704 ns/op
BenchmarkLargeCache02-4 1000000 8561 ns/op
BenchmarkLargeCache05-4 1000000 8328 ns/op
BenchmarkLargeCache10-4 1000000 7837 ns/op
BenchmarkLargeCache20-4 1000000 7418 ns/op
BenchmarkLargeCache50-4 1000000 7702 ns/op
BenchmarkShardedCacheGetExpiring-4 20000000 109 ns/op
BenchmarkShardedCacheGetNotExpiring-4 20000000 67.4 ns/op
BenchmarkShardedCacheGetManyConcurrentExpiring-4 2000000000 50.9 ns/op
BenchmarkShardedCacheGetManyConcurrentNotExpiring-4 100000000 69.2 ns/op

@beppeben
Copy link
Copy Markdown
Author

beppeben commented Jan 8, 2016

did you finally have a look at this?

@patrickmn
Copy link
Copy Markdown
Owner

Not yet, sorry. I'll take a look soon.

@pablodz
Copy link
Copy Markdown

pablodz commented Jan 3, 2024

Found this fork: https://github.com/arp242/zcache

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.

3 participants