Deploy Pyroscope on k8s and analyze golang performance bottlenecks

What is Pyroscope

Pyroscope is an open source application performance analysis tool that can help us discover and solve performance problems in applications. Pyroscope supports multiple programming languages ​​and provides rich performance data, which can help us track the execution of the application and identify performance bottlenecks based on the collected data.

Pyroscope uses a SaaS model for storage, visualization and interactive operations. In this way, we can quickly adjust the monitoring plan and optimize performance. At the same time, Pyroscope also supports use directly in the terminal, which can be easily used for local testing and troubleshooting.


language support:

  1. Golang: Golang is the language originally supported by Pyroscope. Pyroscope supports integrating Pyroscope and obtaining performance data in Golang applications or binaries.

  2. Python: Pyroscope can integrate with Python applications and capture application performance bottlenecks and issues.

  3. Node.js: Pyroscope supports Node.js applications. Integrate Pyroscope within a Node.js application or Node.js binary to obtain performance data.

  4. Ruby: Pyroscope can be integrated into Ruby applications to capture Ruby application performance issues.

  5. Java: Pyroscope also supports Java applications, and Pyroscope can be directly integrated into the code of a Java application to monitor and analyze its performance and bottlenecks.

  6. PHP: Pyroscope supports applications written based on PHP, allowing developers to analyze the performance data of PHP applications through Pyroscope.

  7. .NET: Pyroscope supports .NET-based applications and provides C# and F# client libraries for users to use.


Key features of Pyroscope include:

  1. Low consumption: Pyroscope Agent will not adversely affect production services and will only have a small performance overhead.

  2. Scalability: Advanced X-Factor options such as content density and frequency can be set to make it suitable for high-load environments.

  3. Efficiency: Every run is recorded, all performance data are adjusted to the normal trend line at the same time, the data aggregation is high, and no manual intervention is required.

In short, Pyroscope is an easy-to-install and use performance tracking tool that can provide us with key metrics and insights to help us better track and optimize application performance.


k8s installation:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: pyroscope
  namespace: kube-logging
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pyroscope
  template:
    metadata:
      labels:
        app: pyroscope
    spec:
      containers:
      - name: pyroscope
        image: pyroscope/pyroscope:latest
        ports:
        - containerPort: 4040
        env:
        - name: PYROSCOPE_LOG_LEVEL
          value: "info"
        command: ["sh","-c","/usr/bin/pyroscope server"]
        resources:
          limits:
            cpu: "1"
            memory: "1Gi"
          requests:
            cpu: "500m"
            memory: "500Mi"
        volumeMounts:
        - name: data-dir
          mountPath: /var/lib/pyroscope
      volumes:
      - name: data-dir
        hostPath:
          path: /home/data/
---
apiVersion: v1
kind: Service
metadata:
  name: pyroscope-service
  namespace: kube-logging
spec:
  selector:
    app: pyroscope
  ports:
    - protocol: TCP
      port: 4040
      #targetPort: 32644
      nodePort: 32644
  type: NodePort


start up

#kubectl apply -f ./
#kubectl get pod,svc -n kube-logging
NAME                             READY   STATUS    RESTARTS   AGE
pod/pyroscope-79b5648755-nlvrb   1/1     Running   0          67m

NAME                        TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/pyroscope-service   NodePort   10.107.220.231   <none>        4040:32644/TCP   73m

access

http://k8s_ip:32644
Insert image description here

golang access agent

package main

import (
    "github.com/gin-gonic/gin"
    "github.com/pyroscope-io/pyroscope/pkg/agent/profiler"
)

func main() {
    
    
    profiler.Start(profiler.Config{
    
         //Pyroscope启动
        ApplicationName: "luouoosdfjosjdof.purchases",  //名字
        ServerAddress:   "http://192.168.14.27:32644",  //Pyroscope地址
        SampleRate:      100, //采样率设置,100次采样一次
    })
    r := gin.Default()
    r.GET("/test", func(c *gin.Context) {
    
    
        c.JSON(200, gin.H{
    
    
            "message": "OK",
        })
    })
    r.Run() // default listen serve on 0.0.0.0:8080
}

Make a request

for i in {
    
    1..100};do hey -n 100 -m get  http://localhost:8080/test;sleep 0.1;done

Analyze View

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_43606975/article/details/130363814
Recommended