examples/golang-pgo/README.md
Profile-Guided Optimization (PGO) is a Go compiler feature that uses runtime profiling data to optimize code. Now fully integrated in Go 1.21, PGO is a powerful tool to boost application performance.
PGO enhances performance primarily through two mechanisms:
Take a look at https://go.dev/doc/pgo and https://go.dev/blog/pgo for more information on PGO.
Here are the steps needed to use PGO in the Rideshare example application.
Run the application that we will enable PGO for.
docker-compose up --build --detach
Run the prepared benchmark
go test -bench=BenchmarkApp -count=10 main_test.go
Extract a profile in pprof format with profilecli (see the Profile CLI documentation for further reference)
profilecli query go-pgo \
--query='{service_name="ride-sharing-app"}' \
--from="now-1h" \
--to="now" \
--output=pprof=./default.pgo
This command will create a default.pgo (pprof) file in the current folder (/examples/golang-pgo/rideshare/).
Rebuild the Rideshare application. This will pick up the newly created PGO file automatically.
docker-compose down
docker-compose up --build --detach
(Optional) Verify that the application was built with PGO
docker exec -it golang-pgo-rideshare-go-1 /bin/bash
go version -m main
exit
You should see this line in the output:
...
build -pgo=/go/src/app/default.pgo
...
Run the benchmark again
go test -bench=BenchmarkApp -count=10 main_test.go
(Optional) Use a tool such as benchstat to compare the two benchmarks.