优化代码

This commit is contained in:
GoEdgeLab
2024-04-15 19:37:38 +08:00
parent 8ac6a421c0
commit 4f66f55152
8 changed files with 17 additions and 46 deletions

View File

@@ -282,14 +282,14 @@ func (this *APIStream) handleStatCache(message *pb.NodeStreamMessage) error {
}
sizeFormat := ""
if stat.Size < 1024 {
if stat.Size < (1 << 10) {
sizeFormat = strconv.FormatInt(stat.Size, 10) + " Bytes"
} else if stat.Size < 1024*1024 {
sizeFormat = fmt.Sprintf("%.2f KB", float64(stat.Size)/1024)
} else if stat.Size < 1024*1024*1024 {
sizeFormat = fmt.Sprintf("%.2f MB", float64(stat.Size)/1024/1024)
} else if stat.Size < (1 << 20) {
sizeFormat = fmt.Sprintf("%.2f KiB", float64(stat.Size)/(1<<10))
} else if stat.Size < (1 << 30) {
sizeFormat = fmt.Sprintf("%.2f MiB", float64(stat.Size)/(1<<20))
} else {
sizeFormat = fmt.Sprintf("%.2f GB", float64(stat.Size)/1024/1024/1024)
sizeFormat = fmt.Sprintf("%.2f GiB", float64(stat.Size)/(1<<30))
}
this.replyOk(message.RequestId, "size:"+sizeFormat+", count:"+strconv.Itoa(stat.Count))

View File

@@ -9,7 +9,7 @@ import (
const (
// AccessLogMaxRequestBodySize 访问日志存储的请求内容最大尺寸 TODO 此值应该可以在访问日志页设置
AccessLogMaxRequestBodySize = 2 * 1024 * 1024
AccessLogMaxRequestBodySize = 2 << 20
)
// 日志

View File

@@ -213,7 +213,7 @@ func (this *Node) Start() {
events.Notify(events.EventLoaded)
// 设置rlimit
_ = utils.SetRLimit(1024 * 1024)
_ = utils.SetRLimit(1 << 20)
// 连接API
goman.New(func() {