Merge pull request #82 from alimy/main

optimize #78 support custom configure ActionQPS
pull/87/head
Michael Li 2 years ago committed by GitHub
commit f6a72d3e84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,6 +29,7 @@ SimpleCacheIndex: # 缓存泡泡广场消息流
MaxIndexSize: 200 # 最大缓存条数 MaxIndexSize: 200 # 最大缓存条数
CheckTickDuration: 60 # 循环自检查每多少秒一次 CheckTickDuration: 60 # 循环自检查每多少秒一次
ExpireTickDuration: 300 # 每多少秒后强制过期缓存, 设置为0禁止强制使缓存过期 ExpireTickDuration: 300 # 每多少秒后强制过期缓存, 设置为0禁止强制使缓存过期
ActionQPS: 100 # 添加/删除/更新Post的QPS, 默认100范围设置[10, 10000]
LoggerFile: # 使用File写日志 LoggerFile: # 使用File写日志
SavePath: data/paopao-ce/logs SavePath: data/paopao-ce/logs
FileName: app FileName: app

@ -50,6 +50,7 @@ type SimpleCacheIndexSettingS struct {
MaxIndexSize int MaxIndexSize int
CheckTickDuration int CheckTickDuration int
ExpireTickDuration int ExpireTickDuration int
ActionQPS int
} }
type AlipaySettingS struct { type AlipaySettingS struct {

@ -15,7 +15,6 @@ func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.
getIndexPosts: getIndexPosts, getIndexPosts: getIndexPosts,
maxIndexSize: s.MaxIndexSize, maxIndexSize: s.MaxIndexSize,
indexPosts: make([]*model.PostFormated, 0), 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 checkTick: time.NewTicker(time.Duration(s.CheckTickDuration) * time.Second), // check whether need update index every 1 minute
expireIndexTick: time.NewTicker(time.Second), expireIndexTick: time.NewTicker(time.Second),
} }
@ -27,6 +26,16 @@ func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.
cacheIndex.expireIndexTick.Stop() 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 // start index posts
cacheIndex.atomicIndex.Store(cacheIndex.indexPosts) cacheIndex.atomicIndex.Store(cacheIndex.indexPosts)
go cacheIndex.startIndexPosts() go cacheIndex.startIndexPosts()

Loading…
Cancel
Save