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

Add NativeMemoryMap.hottestKeys, NativeMemoryMap.coldestKeys. #16

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private class OffHeapEviction {

logger.info { "nativeMemoryMap.size = ${nativeMemoryMap.size}" }
logger.info { "nativeMemoryAllocator.nativeMemoryAllocatorMetadata = ${nativeMemoryAllocator.nativeMemoryAllocatorMetadata}" }
logger.info { "nativeMemoryMap.hottestKeys(10) = ${nativeMemoryMap.hottestKeys(numKeys = 10)}" }
logger.info { "nativeMemoryMap.coldestKeys(10) = ${nativeMemoryMap.coldestKeys(numKeys = 10)}" }

val randomIndexValue = nativeMemoryMap.get(key = randomIndex)
randomIndexValue?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ interface NativeMemoryMap<KEY_TYPE : Any, VALUE_TYPE : Any> : BaseNativeMemoryMa
* @return [Set] of [Map.Entry] for the map
*/
val entries: Set<Map.Entry<KEY_TYPE, NativeMemoryBufferMetadata>>

/**
* [Set] of most-used keys in the map.
*
* This will only work if [NativeMemoryMapBackend.CAFFEINE] is used,
* and caffeine is configured with maximumSize eviction policy.
*
* @param numKeys number of keys to return
* @return [Set] of hottest [KEY_TYPE] keys
*/
fun hottestKeys(numKeys: Int): Set<KEY_TYPE>

/**
* [Set] of least-used keys in the map.
*
* This will only work if [NativeMemoryMapBackend.CAFFEINE] is used,
* and caffeine is configured with maximumSize eviction policy.
*
* @param numKeys number of keys to return
* @return [Set] of coldest [KEY_TYPE] keys
*/
fun coldestKeys(numKeys: Int): Set<KEY_TYPE>
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,18 @@ internal class CaffeineNativeMemoryMapImpl<KEY_TYPE : Any, VALUE_TYPE : Any>(
caffeineStats = caffeineCache.stats(),
)

/**
* Override hottestKeys to use caffeine eviction policy.
*/
override fun hottestKeys(numKeys: Int): Set<KEY_TYPE> {
return caffeineCache.policy().eviction().map { it.hottest(numKeys).keys }.orElse(mutableSetOf())
}

/**
* Override coldestKeys to use caffeine eviction policy.
*/
override fun coldestKeys(numKeys: Int): Set<KEY_TYPE> {
return caffeineCache.policy().eviction().map { it.coldest(numKeys).keys }.orElse(mutableSetOf())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@ internal class NativeMemoryMapImpl<KEY_TYPE : Any, VALUE_TYPE : Any>(

override val operationCounters: NativeMemoryMapOperationCounters? = null

override fun hottestKeys(numKeys: Int): Set<KEY_TYPE> = emptySet()

override fun coldestKeys(numKeys: Int): Set<KEY_TYPE> = emptySet()

}
Loading