Member-only story
Continuous Profiling for Go Applications
Using Pyroscope — an open source continuous profiling platform

Profiling a Golang Rideshare App with Pyroscope
In this example, I show a basic use case of how to use Pyroscope — an open-source profiling library — to speed up a Golang application using continuous profiling.
We simulate a “rideshare” company that has three endpoints found in main.go
:
/bike
: calls theOrderBike(searchRadius)
function to order a bike/car
: calls theOrderCar(searchRadius)
function to order a car/scooter
: calls theOrderScooter(searchRadius)
function to order a scooter
I also simulate running 3 distinct servers in 3 different regions (via docker-compose.yml)
- us-east-1
- us-west-1
- eu-west-1
One of the most useful capabilities of Pyroscope is the ability to tag your data in a way that is meaningful to you. In this case, we have two natural divisions, and so we “tag” our data to represent those:
region
: statically tags the region of the server running the codevehicle
: dynamically tags the endpoint (similar to how one might tag controller rails)
Tagging Profiles with a Static Region
Tagging something static, like the region
, can be done in the initialization code in the main()
function:
pyroscope.Start(pyroscope.Config{
ApplicationName: "ride-sharing-app",
ServerAddress: serverAddress,
Logger: pyroscope.StandardLogger,
Tags: map[string]string{"region": os.Getenv("REGION")},
})
Tagging Profiles Dynamically within Functions
Tagging something more dynamically, as we do for the vehicle
tag can be done inside our utility function FindNearestVehicle()
using pyroscope.TagWrapper()
:
func FindNearestVehicle(search_radius int64, vehicle string) {
pyroscope.TagWrapper(context.Background(), pyroscope.Labels("vehicle", vehicle), func(ctx context.Context) {
//…