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

feat: use freecache #416

Merged
merged 9 commits into from
Sep 23, 2022
Merged

feat: use freecache #416

merged 9 commits into from
Sep 23, 2022

Conversation

PengYechang
Copy link
Contributor

Describe what this PR does / why we need it

Does this pull request fix one issue?

Describe how you did it

Describe how to verify it

Special notes for reviews

@sysulq
Copy link
Member

sysulq commented Sep 6, 2022

可以补下单测

@sysulq
Copy link
Member

sysulq commented Sep 6, 2022

可以放在pkg/cache/freecache,方便后面增加其他cache实现

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2022

Codecov Report

Merging #416 (cda6810) into master (a135dc2) will decrease coverage by 0.32%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #416      +/-   ##
==========================================
- Coverage   40.29%   39.97%   -0.33%     
==========================================
  Files          84       84              
  Lines        5611     5611              
==========================================
- Hits         2261     2243      -18     
- Misses       3192     3211      +19     
+ Partials      158      157       -1     
Impacted Files Coverage Δ
pkg/store/gorm/logger.go 14.58% <0.00%> (-37.50%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@sysulq sysulq left a comment

Choose a reason for hiding this comment

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

LGTM

// metric上报
if !l.req.DisableMetric {
defer func() {
prome.LocalCacheHandleHistogram.WithLabelValues(prome.TypeLocalCache, l.req.Name, "EntryCount").Observe(float64(l.cache.EntryCount()))
Copy link
Member

Choose a reason for hiding this comment

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

这里不用defer,可以放在Set之后

// metric上报
if !l.req.DisableMetric {
defer func() {
prome.LocalCacheHandleHistogram.WithLabelValues(prome.TypeLocalCache, l.req.Name, "MissCount").Observe(float64(l.cache.MissCount()))
Copy link
Member

Choose a reason for hiding this comment

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

类似的

}()

func() {
defer func() {
Copy link
Member

Choose a reason for hiding this comment

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

recover可以移除,应该在外层捕获异常

Cache
}

type LocalCacheReq struct {
Copy link
Member

Choose a reason for hiding this comment

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

可以参考下其他组件的模式,通过Config实现Build能力

xlog.Jupiter().Panic("cache NewLocalCache expire err", zap.Any("req", req))
}
if len(req.Name) == 0 {
req.Name = fmt.Sprintf("cache-%d", time.Now().UnixNano())
Copy link
Member

Choose a reason for hiding this comment

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

这里可以考虑基于uuid生成一个唯一key

@@ -0,0 +1,36 @@
package xerr

Copy link
Member

Choose a reason for hiding this comment

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

去掉recover逻辑后,这个文件应该可以删掉

data, err = l.cache.Get([]byte(key))
// metric report
if !l.req.DisableMetric {
prome.CacheHandleGauge.WithLabelValues(prome.TypeLocalCache, l.req.Name, "HitRate").Set(l.cache.HitRate())
Copy link
Member

Choose a reason for hiding this comment

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

看上去这个每次都会遍历几百个segments,感觉可能会对效率有影响

如果自己来统计这个是不是会更高效呢?可以考虑写个benchmark看看

@sysulq sysulq merged commit b5a46e3 into douyu:master Sep 23, 2022
@sysulq sysulq mentioned this pull request Sep 27, 2022
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