[] Go: |
. . Badoo. rakyll Go 1.9. , Go-. Badoo, , , . -, . , , , UID. , , Go.
Go 1.9 : - , CPU-. , . CPU- , , . , . , .
, . Go- Go , , , . , (- ). c Go 1.9 , , , .
. :
runtime/pprof
. Do
, , f
:
func Do(ctx context.Context, labels LabelSet, f func(context.Context))
Do . f, .
labels := pprof.Labels("worker", "purge")
pprof.Do(ctx, labels, func(ctx context.Context) {
// - ...
go update(ctx) //
})
worker:purge
.
. , , .
net/http/pprof
. Profiling Go programs, .
package main
import _ "net/http/pprof"
func main() {
// ...
log.Fatal(http.ListenAndServe("localhost:5555", nil))
}
CPU...
$ go tool pprof http://localhost:5555/debug/pprof/profile
, , tags
. , pprof- , , Go .
(pprof) tags
http-path: Total 80
70 (87.50%): /messages
10 (12.50%): /user
worker: Total 158
158 ( 100%): purge
, (http-path
, worker
) . http-path HTTP-, worker:purge .
, , , /user
.
(pprof) tagfocus="http-path:/user"
(pprof) top10 -cum
Showing nodes accounting for 0.10s, 3.05% of 3.28s total
flat flat% sum% cum cum%
0 0% 0% 0.10s 3.05% main.generateID.func1 /Users/jbd/src/hello/main.go
0.01s 0.3% 0.3% 0.08s 2.44% runtime.concatstring2 /Users/jbd/go/src/runtime/string.go
0.06s 1.83% 2.13% 0.07s 2.13% runtime.concatstrings /Users/jbd/go/src/runtime/string.go
0.01s 0.3% 2.44% 0.02s 0.61% runtime.mallocgc /Users/jbd/go/src/runtime/malloc.go
0 0% 2.44% 0.02s 0.61% runtime.slicebytetostring /Users/jbd/go/src/runtime/string.go
0 0% 2.44% 0.02s 0.61% strconv.FormatInt /Users/jbd/go/src/strconv/itoa.go
0 0% 2.44% 0.02s 0.61% strconv.Itoa /Users/jbd/go/src/strconv/itoa.go
0 0% 2.44% 0.02s 0.61% strconv.formatBits /Users/jbd/go/src/strconv/itoa.go
0.01s 0.3% 2.74% 0.01s 0.3% runtime.memmove /Users/jbd/go/src/runtime/memmove_amd64.s
0.01s 0.3% 3.05% 0.01s 0.3% runtime.nextFreeFast /Users/jbd/go/src/runtime/malloc.go
, http-path:/user
. , /user-.
tagshow
, taghide
tagignore
. , tagignore
, . , /user . worker:purge
http-path:/messages
.
(pprof) tagfocus=
(pprof) tagignore="http-path:/user"
(pprof) tags
http-path: Total 70
70 ( 100%): /messages
worker: Total 158
158 ( 100%): purge
, .
worker:purge
0.07s, messages 0.03s
generateID
.
, . , Go 1.9 beta, . pprofutil
, HTTP- .
Go 1.9 beta 2. , , -. , Go . . !