0%
性能测试
注册 pprof 服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| pprofOpen := c.GetBool("pprof.open") if pprofOpen { pprofPort := c.GetInt("pprof.port") s.pprofSvr = &http.Server{ Addr: ":" + strconv.Itoa(pprofPort), Handler: nil, } go func() { err := s.pprofSvr.ListenAndServe() log.Infof("pprof server down: %+v", err) }() }
c := config.GetConfig() pprofOpen := c.GetBool("pprof.open") if pprofOpen { wg.Add(1) go func() { defer wg.Done() ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := s.pprofSvr.Shutdown(ctx); err != nil { log.Infof("Server Shutdown: ", err) } }() } wg.Wait()
|
1 2
| go tool pprof --seconds 60 http://127.0.0.1:8098/debug/pprof/profile >> web
|
1 2 3
| [pprof] open = true port = 8098
|