Grab服务上的基于配置文件的优化(PGO)

Profile-guided optimisation (PGO) is a technique where CPU profile data for an application is collected and fed back into the next compiler build of Go application. The compiler then uses this CPU profile data to optimise the performance of that build by around 2-14% currently (future releases could likely improve this figure further).

Profile-guided optimisation (PGO) 是一种技术,其中收集应用程序的 CPU 分析数据,并将其反馈到下一个 Go 应用程序的编译器构建中。然后,编译器使用这些 CPU 分析数据来优化该构建的性能,目前大约可以提高约 2-14% (未来版本可能进一步提高这个数字)。

High level view of how PGO works

PGO 的工作原理概览

PGO is a widely used technique that can be implemented with many programming languages. When it was released in May 2023, PGO was introduced as a preview in Go 1.20.

PGO是一种广泛使用的技术,可以在许多编程语言中实现。当它于2023年5月发布时,PGO在Go 1.20中作为预览版引入。

Enabling PGO on a service

在服务上启用PGO

Profile the service to get pprof file

对服务进行配置文件分析以获取pprof文件

First, make sure that your service is built using Golang version v1.20 or higher, as only these versions support PGO.

首先,请确保您的服务使用的是 Golang 版本 v1.20 或更高版本,因为只有这些版本支持 PGO。

Next, enable pprof in your service.

接下来,在您的服务中启用pprof

If it’s already enabled, you can use the following command to capture a 6-minute profile and save it to /tmp/pprof.

如果已经启用,您可以使用以下命令捕获6分钟的配置文件并保存到/tmp/pprof

curl 'http://localhost:6060/debug/pprof/profile?seconds=360' -o /tmp/pprof

Enabled PGO on the service

在服务上启用PGO

TalariaDB: TalariaDB is a distributed, highly available, and low latency time-series database for Presto open sourced by Grab.

TalariaDB:TalariaDB是Grab开源的用于Presto的分布式、高可用和低延迟的时序数据库。

It is a service that runs on an EKS cluster and is entirely managed by our team, we will use it as an example here.

这是一个在 EKS 集群上运行并完全由我们团队管理的服务,我们将在这里以此为例。

Since the cluster deployment relies on a Docker image, we only need to update the Docker image’s go build command to include -PGO=./talaria.PGO. The talaria.PGO file is a pprof profile collected from production services over a span of 360 seconds.

由于集群部署依赖于 Docker 镜像,我们只需要更新 Docker 镜像的 go build 命令,包括 -PGO=./talaria.PGOtalaria.PGO 文件是从生产服务中收集的 pprof 配置文件,持续时间为 3...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.3. UTC+08:00, 2024-11-26 00:04
浙ICP备14020137号-1 $访客地图$