6
头图

After the website is online, increased traffic or short-term functional failures will cause a very bad user experience. How to quickly find the performance bottleneck at this time? Usually when the CPU reaches 100%, it is sometimes difficult to replicate and find the key problem points.

In this article, we will introduce a set of tools called Pyroscope, which allows developers to quickly find the code with performance bottlenecks. Pyroscope can currently support Python, Ruby or Go environments. The author of this article will introduce the Go environment.

image.png

What is Pyroscope?

Pyroscope is a set of open source real-time performance monitoring platform. The simple server and agent architecture allows developers to easily monitor code performance. Whether you are looking for performance data within 10 seconds or minutes, it can be displayed quickly and instantly. Don't worry about installing this monitor will cause any performance burden. The storage behind Pyroscope uses Badger's Key-Value database, which is very good in performance. Currently only 3 languages (Python, Ruby and Go) are supported. NodeJS is expected to be supported in the future. Assuming you have not introduced any performance analysis tools or platforms, Pyroscope will be your best choice.

Pyroscope architecture

If you are planning to find a performance analysis tool platform, Pyroscope provides three advantages, so that developers can use it with confidence

  • Low CPU usage, will not affect existing platforms
  • Data can be stored for several years, and the data can be viewed in 10 seconds with fine granularity
  • Compress storage data to reduce wasted hard disk space
  • The architecture has only Server and Agent. In addition to the Go language, Python and Ruby App both use the pyroscope command to start related apps to monitor system performance.

image.png

Start the Pyroscope service

There are two ways to start. The first is to start directly with the docker command.

$ docker run -it -p 4040:4040 pyroscope/pyroscope:latest server

The other can be started with docker-compose.

---
services:
  pyroscope:
    image: "pyroscope/pyroscope:latest"
    ports:
      - "4040:4040"
    command:
      - "server"

Install Agent

image.png

Use in Go language

This article uses Go language as an example, first import package

import "github.com/pyroscope-io/pyroscope/pkg/agent/profiler"

Then write the following code in main.go:

profiler.Start(profiler.Config{
    ApplicationName: "simple.golang.app",
    ServerAddress:   "http://pyroscope:4040",
})

Among them, http://pyroscope can be replaced with a custom hostname, and then open the above URL to see the performance monitoring screen.
image.png
image.png
image.png

Used in Python and Ruby languages
# If using Python
$ pyroscope exec python manage.py runserver 

# If using Ruby
$ pyroscope exec rails server    

Experience

This set of tools is very convenient. Although you can use pprof to quickly find problems in the Go language, it is inevitable that you still need to manually find some performance bottlenecks. With this platform, all apps can be monitored. If you have any problems, you can quickly use Pyroscope to check which codes are wrong.

Author: Little Devil Original: http://t.cn/A6c0G3dm


民工哥
26.4k 声望56.7k 粉丝

10多年IT职场老司机的经验分享,坚持自学一路从技术小白成长为互联网企业信息技术部门的负责人。2019/2020/2021年度 思否Top Writer