Skip to content

Commit

Permalink
change execution-cache to sized-based cache implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
timl3136 committed Feb 14, 2025
1 parent 4b30b13 commit e28eb59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion service/history/execution/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package execution

import (
"context"
"reflect"
"sync/atomic"
"time"

Expand Down Expand Up @@ -108,14 +109,21 @@ const (
cacheReleased int32 = 1
)

// GetCacheItemSize returns the size of interface{} using reflect
func GetCacheItemSize(i interface{}) uint64 {
return uint64(reflect.TypeOf(i).Size())
}

// NewCache creates a new workflow execution context cache
func NewCache(shard shard.Context) Cache {
opts := &cache.Options{}
config := shard.GetConfig()
opts.InitialCapacity = config.HistoryCacheInitialSize()
opts.TTL = config.HistoryCacheTTL()
opts.Pin = true
opts.MaxCount = config.HistoryCacheMaxSize()
opts.MaxSize = uint64(config.HistoryCacheMaxSize())

opts.GetCacheItemSizeFunc = GetCacheItemSize

return &cacheImpl{
Cache: cache.New(opts),
Expand Down
2 changes: 1 addition & 1 deletion service/history/execution/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *historyCacheSuite) TestHistoryCacheBasic() {
}

func (s *historyCacheSuite) TestHistoryCachePinning() {
s.mockShard.GetConfig().HistoryCacheMaxSize = dynamicconfig.GetIntPropertyFn(2)
s.mockShard.GetConfig().HistoryCacheMaxSize = dynamicconfig.GetIntPropertyFn(10)
domainID := "test_domain_id"
s.cache = NewCache(s.mockShard)
we := types.WorkflowExecution{
Expand Down

0 comments on commit e28eb59

Please sign in to comment.