go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

How to set SlowThreshold in api and rpc?

Open techdatas opened this issue 1 year ago • 9 comments
trafficstars

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)

techdatas avatar Feb 04 '24 10:02 techdatas

What's the duration in logs for slowcall? Slower than 1 second?

kevwan avatar Feb 04 '24 15:02 kevwan

not more than 600ms

techdatas avatar Feb 05 '24 01:02 techdatas

i have tried to set up the slow threshold on statconf but the log still show the slowness Middlewares: StatConf: SlowThreshold: 1000ms

techdatas avatar Feb 05 '24 13:02 techdatas

截屏2024-02-05 22 31 56 not sure if it's a problem or not duration > slowThreshold.Load() still use slowThreshold instead of conf.SlowThreshold

techdatas avatar Feb 05 '24 14:02 techdatas

rpc客户端慢日志是单独设置的 zrpc.SetClientSlowThreshold(time.Second * time.Duration(c.RpcClientSlowThreshold)) 希望官方可以给每个rpc单独配置

bigrocs avatar May 15 '24 03:05 bigrocs

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

Issues-translate-bot avatar May 15 '24 03:05 Issues-translate-bot

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:

Issues-translate-bot avatar May 27 '24 04:05 Issues-translate-bot

在 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{
        ...
    }
}

cosmosisis avatar May 27 '24 04:05 cosmosisis