diff --git "a/docs/proposal/016-\345\205\263\344\272\216\344\275\277\347\224\250pyroscope\347\224\250\344\272\216\346\200\247\350\203\275\350\260\203\350\257\225\347\232\204\350\256\276\350\256\241.md" "b/docs/proposal/016-\345\205\263\344\272\216\344\275\277\347\224\250pyroscope\347\224\250\344\272\216\346\200\247\350\203\275\350\260\203\350\257\225\347\232\204\350\256\276\350\256\241.md" index d2313bc7..b8926cd5 100644 --- "a/docs/proposal/016-\345\205\263\344\272\216\344\275\277\347\224\250pyroscope\347\224\250\344\272\216\346\200\247\350\203\275\350\260\203\350\257\225\347\232\204\350\256\276\350\256\241.md" +++ "b/docs/proposal/016-\345\205\263\344\272\216\344\275\277\347\224\250pyroscope\347\224\250\344\272\216\346\200\247\350\203\275\350\260\203\350\257\225\347\232\204\350\256\276\350\256\241.md" @@ -1,6 +1,6 @@ | 编号 | 作者 | 发表时间 | 变更时间 | 版本 | 状态 | | ----- | ----- | ----- | ----- | ----- | ----- | -| 016| 北野 | 2023-02-15 | 2023-02-15 | v1.0 | 提议 | +| 016| 北野 | 2023-02-15 | 2023-02-16 | v1.1 | 提议 | ### 概述 Pyroscope 是一个开源的持续性能剖析平台。它能够帮你: @@ -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 @@ -32,8 +41,6 @@ Pyroscope 是一个开源的持续性能剖析平台。它能够帮你: ... ``` - - ### 参考文档 * [pyroscope](https://github.com/pyroscope-io/pyroscope) * [pyroscope client](https://github.com/pyroscope-io/client) @@ -41,3 +48,6 @@ Pyroscope 是一个开源的持续性能剖析平台。它能够帮你: ### 更新记录 #### v1.0(2023-02-15) - 北野 * 初始文档 + +#### v1.1(2023-02-16) - 北野 +* 添加参考实现 diff --git a/internal/conf/config.yaml b/internal/conf/config.yaml index f0465e41..6ea7d3c6 100644 --- a/internal/conf/config.yaml +++ b/internal/conf/config.yaml @@ -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配置 diff --git a/internal/conf/settting.go b/internal/conf/settting.go index 6e08ce66..a9b2643d 100644 --- a/internal/conf/settting.go +++ b/internal/conf/settting.go @@ -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 { diff --git a/internal/dao/cache/cache.go b/internal/dao/cache/cache.go index 773c9a2f..e2be7a32 100644 --- a/internal/dao/cache/cache.go +++ b/internal/dao/cache/cache.go @@ -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) }