Skip to content

Commit

Permalink
Merge pull request #200 from alimy/pr-bigcache-hardcachesize
Browse files Browse the repository at this point in the history
optimize BigCacheIndex add HardMaxCacheSize to adjust cache size
  • Loading branch information
alimy committed Feb 16, 2023
2 parents fb42e72 + f0c4320 commit 7bf676c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| 编号 | 作者 | 发表时间 | 变更时间 | 版本 | 状态 |
| ----- | ----- | ----- | ----- | ----- | ----- |
| 016| 北野 | 2023-02-15 | 2023-02-15 | v1.0 | 提议 |
| 016| 北野 | 2023-02-15 | 2023-02-16 | v1.1 | 提议 |

### 概述
Pyroscope 是一个开源的持续性能剖析平台。它能够帮你:
Expand All @@ -13,16 +13,25 @@ Pyroscope 是一个开源的持续性能剖析平台。它能够帮你:
* 开发环境下启用Pyroscope,但是部署环境下禁用。

### 方案
#### 设计要点
* 使用//go:build pyroscope 可选编译app集成Pyroscope功能
* config.yaml中添加`Pyroscope` 功能来启用Pyroscope

#### 设计细节
* 参考实现(PR):
[add Pyroscope support #199](https://github.com/rocboss/paopao-ce/pull/199)

### 疑问

1. 为什么要引入Pyroscope?
用于开发环境下对paopao-ce进行性能优化。

2. 如何开启这个功能?
在配置文件config.yaml中的`Features`中添加`Pyroscope`功能项开启该功能:
2. 如何开启这个功能?
* 构建时将 `pyroscope` 添加到TAGS中:
```sh
make run TAGS='pyroscope'
```
* 在配置文件config.yaml中的`Features`中添加`Pyroscope`功能项开启该功能:
```yaml
...
# features中加上 Friendship
Expand All @@ -32,12 +41,13 @@ Pyroscope 是一个开源的持续性能剖析平台。它能够帮你:
...
```



### 参考文档
* [pyroscope](https://github.com/pyroscope-io/pyroscope)
* [pyroscope client](https://github.com/pyroscope-io/client)

### 更新记录
#### v1.0(2023-02-15) - 北野
* 初始文档

#### v1.1(2023-02-16) - 北野
* 添加参考实现
1 change: 1 addition & 0 deletions internal/conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ SimpleCacheIndex: # 缓存泡泡广场消息流
ExpireTickDuration: 300 # 每多少秒后强制过期缓存, 设置为0禁止强制使缓存过期
BigCacheIndex: # 使用BigCache缓存泡泡广场消息流
MaxIndexPage: 1024 # 最大缓存页数,必须是2^n, 代表最大同时缓存多少页数据
HardMaxCacheSize: 256 # 最大缓存大小(MB),0表示无限制
Verbose: False # 是否打印cache操作的log
ExpireInSecond: 300 # 多少秒(>0)后强制过期缓存
Pyroscope: # Pyroscope配置
Expand Down
7 changes: 4 additions & 3 deletions internal/conf/settting.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ type SimpleCacheIndexSettingS struct {
}

type BigCacheIndexSettingS struct {
MaxIndexPage int
ExpireInSecond time.Duration
Verbose bool
MaxIndexPage int
HardMaxCacheSize int
ExpireInSecond time.Duration
Verbose bool
}

type AlipaySettingS struct {
Expand Down
14 changes: 7 additions & 7 deletions internal/dao/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (

func NewBigCacheIndexService(ips core.IndexPostsService, ams core.AuthorizationManageService) (core.CacheIndexService, core.VersionInfo) {
s := conf.BigCacheIndexSetting

config := bigcache.DefaultConfig(s.ExpireInSecond)
config.Shards = s.MaxIndexPage
config.Verbose = s.Verbose
config.MaxEntrySize = 10000
config.Logger = logrus.StandardLogger()
cache, err := bigcache.NewBigCache(config)
c := bigcache.DefaultConfig(s.ExpireInSecond)
c.Shards = s.MaxIndexPage
c.HardMaxCacheSize = s.HardMaxCacheSize
c.Verbose = s.Verbose
c.MaxEntrySize = 10000
c.Logger = logrus.StandardLogger()
cache, err := bigcache.NewBigCache(c)
if err != nil {
logrus.Fatalf("initial bigCahceIndex failure by err: %v", err)
}
Expand Down

0 comments on commit 7bf676c

Please sign in to comment.