go-zero
go-zero copied to clipboard
How to set SlowThreshold in api and rpc?
i have set the sqlx and zrpc ,but still show slow records in RPC and API log ,can you please help to let me know how to set the slowthreshold properly ?
handler/loghandler.go:131 "caller":"serverinterceptors/statinterceptor.go:88","content":"[RPC] slowcall
zrpc.SetClientSlowThreshold(time.Millisecond * 1000) sqlx.SetSlowThreshold(time.Millisecond * 1000)
What's the duration in logs for slowcall? Slower than 1 second?
not more than 600ms
i have tried to set up the slow threshold on statconf but the log still show the slowness Middlewares: StatConf: SlowThreshold: 1000ms
not sure if it's a problem or not duration > slowThreshold.Load() still use slowThreshold instead of conf.SlowThreshold
rpc客户端慢日志是单独设置的 zrpc.SetClientSlowThreshold(time.Second * time.Duration(c.RpcClientSlowThreshold)) 希望官方可以给每个rpc单独配置
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
The rpc client slow log is set separately zrpc.SetClientSlowThreshold(time.Second * time.Duration(c.RpcClientSlowThreshold)) I hope the official can configure it separately for each rpc
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
In the svc file (such as app/XXX/cmd/rpc/internal/svc/serviceContext.go), use the following statement:
在 rpc 文件的 svc 中(如 app/XXX/cmd/rpc/internal/svc/serviceContext.go), 新增如下语句即可:
func NewServiceContext(c config.Config) *ServiceContext {
...
// 设置 slow call 阈值为 1min
zrpc.SetClientSlowThreshold(time.Second * 60 * 1)
sqlx.SetSlowThreshold(time.Second * 60 * 1)
return &ServiceContext{
...
}
}