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

remove the event cache initial size and refactor putInternal #4698

Merged
merged 8 commits into from Aug 8, 2023

Conversation

yujieli-temporal
Copy link
Contributor

@yujieli-temporal yujieli-temporal commented Jul 28, 2023

What changed?
remove the cache initial size from lru cache and related configs. also refactor putInternal to better support different scenarios.

and added more unittests for cache size.

Why?
in #4621 I change the history cache to use item bytes instead item count. However it accidentally touched default number of key when cache initialized

How did you test it?
unittest

Potential risks

Is hotfix candidate?

@yujieli-temporal yujieli-temporal force-pushed the yj/cache_default_fix branch 3 times, most recently from e19feac to 64c40ae Compare July 28, 2023 02:34
Copy link
Member

@dnr dnr left a comment

Choose a reason for hiding this comment

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

Just a thought: this whole thing is just to initialize the size for some long-lived maps. It seems to me the performance impact should be negligible at best, probably not even measurable, since the maps will quickly grow to their eventual size and stay around there. Why don't we just get rid of the whole thing and let Go manage the map size?

@yujieli-temporal
Copy link
Contributor Author

temporarily closed this PR, we will revisit the history cache in the future.

common/cache/lru.go Show resolved Hide resolved
common/cache/lru_test.go Show resolved Hide resolved
@yujieli-temporal yujieli-temporal marked this pull request as ready for review August 1, 2023 19:48
@yujieli-temporal yujieli-temporal requested a review from a team as a code owner August 1, 2023 19:48
common/cache/lru.go Outdated Show resolved Hide resolved
@yujieli-temporal yujieli-temporal changed the title fix the event cache initialize size and rename the config WIP | fix the event cache initialize size and rename the config Aug 2, 2023
@@ -392,3 +420,116 @@ func TestCache_ItemHasCacheSizeDefined(t *testing.T) {

endWG.Wait()
}

func TestCache_ItemHasCacheSizeDefined_PutWithNewKeys(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added more tests below for PutWithNewKey/PutWithSameKey and PutIfNotExistWithNewKey/PutIfNotExistWithSameKey below

@yujieli-temporal yujieli-temporal changed the title WIP | fix the event cache initialize size and rename the config remove the event cache initial size and refactor putInternal Aug 3, 2023
@@ -108,9 +108,8 @@ func NewEventsBlobCache(
) *XDCCacheImpl {
return &XDCCacheImpl{
cache: cache.New(util.Max(xdcMinCacheSize, maxBytes), &cache.Options{
InitialCapacity: xdcMinCacheSize,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

xdc use same default value for cache init and max

common/cache/lru.go Outdated Show resolved Hide resolved
@@ -152,7 +152,7 @@ func New(maxSize int, opts *Options) Cache {

return &lru{
byAccess: list.New(),
byKey: make(map[interface{}]*list.Element, opts.InitialCapacity),
byKey: make(map[interface{}]*list.Element),
ttl: opts.TTL,
maxSize: maxSize,
Copy link
Member

Choose a reason for hiding this comment

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

not for this PR, but if I were writing code using this, I'd want to control both max total size and max element size separately, so that I can prevent one element from using the entire cache space. just an idea for the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, I think is future improvement for the cache.

common/cache/lru.go Outdated Show resolved Hide resolved
common/cache/lru.go Outdated Show resolved Hide resolved
Copy link
Member

@dnr dnr left a comment

Choose a reason for hiding this comment

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

looks good, just two tiny possible simplifications

common/cache/lru.go Outdated Show resolved Hide resolved
common/cache/lru.go Outdated Show resolved Hide resolved
@yujieli-temporal yujieli-temporal merged commit a608721 into main Aug 8, 2023
10 checks passed
@yujieli-temporal yujieli-temporal deleted the yj/cache_default_fix branch August 8, 2023 08:31
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.

None yet

3 participants