프로파일링
Teleport v18.9Teleport는 Go의 진단 기능을 활용하여 프로파일링 데이터를 수집하고 내보냅니다. Teleport Debug Service는 관리자가 시작 시 pprof 엔드포인트를 활성화하지 않고도 진단 프로파일을 수집할 수 있게 합니다.
Teleport는 Go의 진단 기능을 활용하여 프로파일링 데이터를 수집하고 내보냅니다. 프로파일은 CPU 급증의 원인, 메모리 누수 출처, 또는 데드락 이유를 파악하는 데 도움이 됩니다.
Debug Service 사용#
Teleport Debug Service는 관리자가 시작 시 pprof 엔드포인트를 활성화하지 않고도 진단 프로파일을 수집할 수 있게 합니다. 기본적으로 활성화된 이 서비스는 로컬 전용 접근을 보장하며 동일한 인스턴스 내부에서 사용해야 합니다.
teleport debug profile은 pprof 프로파일 목록을 수집합니다. 압축된 tarball(.tar.gz)을 STDOUT으로 출력합니다. tar를 사용하여 압축을 풀거나 결과를 파일로 저장할 수 있습니다.
기본적으로 goroutine, heap, profile 프로파일을 수집합니다.
수집된 각 프로파일은 tarball 내부에 해당 파일을 가집니다. 예를 들어 goroutine,trace,heap을 수집하면 goroutine.pprof, trace.pprof, heap.pprof 파일이 생성됩니다.
# Collect default profiles and save to a file.
$ teleport debug profile > pprof.tar.gz
$ tar xvf pprof.tar.gz
# Collect default profiles and decompress it.
$ teleport debug profile | tar xzv -C ./
# Collect "trace" and "mutex" profiles and save to a file.
$ teleport debug profile trace,mutex > pprof.tar.gz
# Collect profiles setting the profiling time in seconds
$ teleport debug profile -s 20 trace > pprof.tar.gz
Teleport 구성이 기본 경로(/etc/teleport.yaml)에 위치하지 않은 경우,
-c/--config 플래그를 사용하여 CLI 명령에 해당 위치를 지정해야 합니다.
Kubernetes 클러스터에서 Teleport를 실행 중인 경우 대화형 세션 없이 직접 로컬 디렉터리로 프로파일을 수집할 수 있습니다:
$ kubectl -n teleport exec my-pod -- teleport debug profile > pprof.tar.gz
내용을 추출한 후 go tool 명령으로 탐색하고 시각화할 수 있습니다:
# Opens the terminal interactive explorer
$ go tool pprof heap.pprof
# Opens the web visualizer
$ go tool pprof -http : heap.pprof
# Visualize trace profiles
$ go tool trace trace.pprof
진단 엔드포인트 사용#
프로파일링 엔드포인트는 --debug 플래그가 제공된 경우에만 활성화됩니다.
Teleport의 진단 HTTP 엔드포인트는 기본적으로 비활성화되어 있습니다. 다음을 통해 활성화할 수 있습니다:
Command line
진단 엔드포인트가 수신 대기할 로컬 주소로 `--diag-addr` 플래그를 설정하여
`teleport` 인스턴스를 시작합니다:
```code
$ sudo teleport start --debug --diag-addr=127.0.0.1:3000
```
Config file
`teleport` 인스턴스의 구성 파일(기본값 `/etc/teleport.yaml`)을 편집하여
다음을 포함시킵니다:
```yaml
teleport:
diag_addr: 127.0.0.1:3000
```
디버그 로그를 활성화하려면:
```yaml
log:
severity: DEBUG
```
진단 엔드포인트에 연결할 수 있는지 확인하세요
이제 Teleport가 진단 엔드포인트를 제공하고 있는지 확인합니다:
```code
$ curl http://127.0.0.1:3000/healthz
```
프로파일 수집#
Go의 표준 프로파일링 엔드포인트는 http://127.0.0.1:3000/debug/pprof/에서 제공됩니다.
프로파일을 검색하려면 원하는 프로파일 유형에 해당하는 엔드포인트로 요청을 전송해야 합니다. 문제를 디버깅할 때는 일정 기간 동안 일련의 프로파일을 수집하는 것이 도움이 됩니다.
CPU#
CPU 프로파일은 사용자가 지정한 기간 동안 수집된 실행 통계를 보여줍니다:
# Download the profile into a file:
$ curl -o cpu.profile http://127.0.0.1:3000/debug/pprof/profile?seconds=30
# Visualize the profile
$ go tool pprof -http : cpu.profile
Goroutine#
Goroutine 프로파일은 시스템에서 실행 중인 모든 goroutine의 스택 추적을 보여줍니다:
# Download the profile into a file:
$ curl -o goroutine.profile http://127.0.0.1:3000/debug/pprof/goroutine
# Visualize the profile
$ go tool pprof -http : goroutine.profile
Heap#
Heap 프로파일은 시스템에 할당된 객체를 보여줍니다:
# Download the profile into a file:
$ curl -o heap.profile http://127.0.0.1:3000/debug/pprof/heap
# Visualize the profile
$ go tool pprof -http : heap.profile
Trace#
Trace 프로파일은 사용자가 지정한 기간 동안 Go 런타임이 수집하는 스케줄링, 시스템 호출, 가비지 컬렉션, 힙 크기 및 기타 이벤트를 캡처합니다:
# Download the profile into a file:
$ curl -o trace.out http://127.0.0.1:3000/debug/pprof/trace?seconds=5
# Visualize the profile
$ go tool trace trace.out
추가 자료#
- Go 생태계의 진단에 대한 더 많은 정보: https://go.dev/doc/diagnostics
- Go의 프로파일링 엔드포인트: https://golang.org/pkg/net/http/pprof/
- Go 프로그램 프로파일링에 대한 심층 분석: https://go.dev/blog/pprof