跳转至

PPROF

启动 pprof UI。

安装#

go get github.com/rookie-ninja/rk-boot/v2
go get github.com/rookie-ninja/rk-grpc/v2

选项#

名字 描述 类型 默认值
grpc.pprof.enabled 启动 pprof web UI boolean false
grpc.pprof.path pprof web 界面路径 string pprof

快速开始#

1.创建并编译 protocol buffer#

使用 buf 编译 protocol buf

2.创建 boot.yaml#

---
grpc:
  - name: greeter
    port: 8080
#   gwPort: 8081                  # 可选项,如果不指定,会使用与 port 一样的端口
    enabled: true
    enableRkGwOption: true
    pprof:
      enabled: true
#      path: ""

3.创建 main.go#

package main

import (
  "context"
  "github.com/rookie-ninja/rk-boot/v2"
  "github.com/rookie-ninja/rk-demo/api/gen/v1"
  "github.com/rookie-ninja/rk-grpc/v2/boot"
  "google.golang.org/grpc"
)

func main() {
  boot := rkboot.NewBoot()

  // register grpc
  entry := rkgrpc.GetGrpcEntry("greeter")
  entry.AddRegFuncGrpc(registerGreeter)
  entry.AddRegFuncGw(greeter.RegisterGreeterHandlerFromEndpoint)

  // Bootstrap
  boot.Bootstrap(context.TODO())

  // Wait for shutdown sig
  boot.WaitForShutdownSig(context.TODO())
}

func registerGreeter(server *grpc.Server) {
  greeter.RegisterGreeterServer(server, &GreeterServer{})
}

type GreeterServer struct{}

func (server *GreeterServer) Hello(ctx context.Context, _ *greeter.HelloRequest) (*greeter.HelloResponse, error) {
  return &greeter.HelloResponse{
    Message: "hello!",
  }, nil
}

4.验证#

PPROF: http://localhost:8080/pprof

Cheers#