首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >net/http/pprof

net/http/pprof

作者头像
酷走天涯
发布2019-05-26 08:54:03
8030
发布2019-05-26 08:54:03
举报

pprof包通过它的HTTP服务端提供pprof可视化工具期望格式的运行时剖面文件数据服务

package main
import (
     _ "net/http/pprof" 
    "net/http"
)
func main() {
    http.ListenAndServe("localhost:8082", nil)
}

只需要导入 包"net/http/pprof" 即可,其余的工作就是进行性能查看了

方式 1 你可以在浏览器中输入 http://localhost:8082/debug/pprof/

image.png

方式 2 查看周期30秒的CPU性能切面

go tool pprof http://localhost:8082/debug/pprof/profile

image.png

方式3 查看堆切面

go tool pprof http://localhost:8082/debug/pprof/heap

方式 4 查看go协程阻塞切面

go tool pprof http://localhost:8082/debug/pprof/block


安装可视化工具

第一步 先升级rvm

先替换下载镜像 https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git

以此执行下面的指令

rvm autolibs read-only

curl -L get.rvm.io | bash -s stable 

source /Users/xujie/.rvm/scripts/rvm

查看版本

ruby -v

第二步 安装

brew install graphviz

image.png


可视化工具2
git clone https://github.com/brendangregg/FlameGraph.git

进入下载好的文件夹中

cd /Users/xujie/FlameGraph 

执行下面命令

 cp flamegraph.pl /usr/local/bin

查看是否安装成功

flamegraph.pl -h

image.png

安装 go-torch

go get -v github.com/uber/go-torch

image.png

  go-torch -u http://localhost:8082/login

压力测试

工具在这里 https://github.com/adjust/go-wrk

git clone git://github.com/adeven/go-wrk.git 
cd go-wrk
go build

image.png

请确保将go build 编译后的执行文件 放在系统go/bin文件夹中,并且保证您的环境变量配置正确

配置演示如下

xudeMacBook-Air:~ xujie$ export GOPATH=/Users/xujie/go
xudeMacBook-Air:~ xujie$ export GOBIN=$GOPATH/bin
xudeMacBook-Air:~ xujie$ export PATH=$PATH:$GOBIN

下面我们看一下这个压力测试工具怎么使用

go-wrk [flags] url

 -H="User-Agent: go-wrk 0.1 bechmark\nContent-Type: text/html;": the http headers sent separated by '\n'
    -c=100: 最大连接数
    -k=true: if keep-alives are disabled
    -i=false: if TLS security checks are disabled
    -m="GET": the http request method
    -n=1000: the total number of calls processed // 启动的协程数
    -t=1: the numbers of threads used // 线程数量
    -b="" the http request body
go-wrk -c=400 -t=8 -n=100000  http://localhost:8080/index.html

image.png

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.12.25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装可视化工具
  • 可视化工具2
  • 压力测试
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档