From 7a25bae54bc0356a016b8e78f104a47edd0e2006 Mon Sep 17 00:00:00 2001 From: alimy Date: Sat, 11 Jun 2022 12:16:21 +0800 Subject: [PATCH] optimize #78 support custom configure ActionQPS to adjust internal action event send --- config.yaml.sample | 1 + internal/conf/settting.go | 1 + internal/dao/cache_index.go | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.yaml.sample b/config.yaml.sample index 65b65eba..7809806b 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -29,6 +29,7 @@ SimpleCacheIndex: # 缓存泡泡广场消息流 MaxIndexSize: 200 # 最大缓存条数 CheckTickDuration: 60 # 循环自检查每多少秒一次 ExpireTickDuration: 300 # 每多少秒后强制过期缓存, 设置为0禁止强制使缓存过期 + ActionQPS: 100 # 添加/删除/更新Post的QPS, 默认100,范围设置[10, 10000] LoggerFile: # 使用File写日志 SavePath: data/paopao-ce/logs FileName: app diff --git a/internal/conf/settting.go b/internal/conf/settting.go index aa37e923..90ec2c3e 100644 --- a/internal/conf/settting.go +++ b/internal/conf/settting.go @@ -50,6 +50,7 @@ type SimpleCacheIndexSettingS struct { MaxIndexSize int CheckTickDuration int ExpireTickDuration int + ActionQPS int } type AlipaySettingS struct { diff --git a/internal/dao/cache_index.go b/internal/dao/cache_index.go index 435b5d68..ce213789 100644 --- a/internal/dao/cache_index.go +++ b/internal/dao/cache_index.go @@ -15,7 +15,6 @@ func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model. getIndexPosts: getIndexPosts, maxIndexSize: s.MaxIndexSize, indexPosts: make([]*model.PostFormated, 0), - indexActionCh: make(chan core.IndexActionT, 100), // optimize: size need configure by custom checkTick: time.NewTicker(time.Duration(s.CheckTickDuration) * time.Second), // check whether need update index every 1 minute expireIndexTick: time.NewTicker(time.Second), } @@ -27,6 +26,16 @@ func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model. cacheIndex.expireIndexTick.Stop() } + // indexActionCh capacity custom configure by conf.yaml need in [10, 10000] + // or re-compile source to adjust min/max capacity + capacity := s.ActionQPS + if capacity < 10 { + capacity = 10 + } else if capacity > 10000 { + capacity = 10000 + } + cacheIndex.indexActionCh = make(chan core.IndexActionT, capacity) + // start index posts cacheIndex.atomicIndex.Store(cacheIndex.indexPosts) go cacheIndex.startIndexPosts()