Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tracing for Granularity

JBD
June 02, 2018

Tracing for Granularity

JBD

June 02, 2018
Tweet

More Decks by JBD

Other Decks in Programming

Transcript

  1. @rakyll Without an SLO, your team has no principled way

    of saying what level of downtime is acceptable. • Error rate • Latency or throughput expectations Service Level Objectives (SLOs)
  2. @rakyll 28 ms 100 ms 172 ms 56 ms 356

    ms what user sees what else we can see sec.Check auth.AccessToken cache.Lookup spanner.Query GET /messages
  3. @rakyll 182 ms 56 ms 245 ms what user sees

    what else we can see sec.Check auth.AccessToken GET /messages 7 ms cache.Lookup
  4. @rakyll Go is the language to write servers. Many runtime

    activities occur during the program execution: • scheduling • memory allocation • garbage collection Hard to associate a request with its impact on the runtime.
  5. “ @rakyll There is no easy way to tell why

    latency is high for certain requests. Is it due to GC, scheduler or syscalls? Can you review the code and tell us why? -SRE
  6. @rakyll Execution tracer $ go tool trace • Reports fine-grained

    runtime events in the lifetime of a goroutine. • Reports utilization of CPU cores. But cannot easily tell how handling a request impacts the runtime.
  7. @rakyll 28 ms 100 ms 172 ms 56 ms 356

    ms GET /messages auth.AccessToken cache.Lookup spanner.Query GET /messages
  8. @rakyll 5 68µs 8 123µs networking serialization + deserialization garbage

    collection blocking syscall what actually happens 172 ms auth.AccessToken
  9. @rakyll How? • Mark sections in code using runtime/trace. •

    Enable execution tracer temporarily and record data. • Examine the recorded data.
  10. @rakyll Go 1.11 introduces... • User regions, tasks and annotations.

    • Association between user code and runtime. • Association with distributed traces.
  11. @rakyll Go 1.11 runtime/trace import “runtime/trace” ctx, task := trace.NewTask(ctx,

    “myHandler”) defer task.End() // Handler code here....
  12. @rakyll region #1 task #1 Go 1.11 runtime/trace region #2

    region #3 region #4 region #5 goroutine #1 goroutine #4 goroutine #5
  13. @rakyll $ curl http://server:6060/debug/pprof/trace?seconds=5 -o trace.out $ go tool trace

    trace.out 2018/05/04 10:39:59 Parsing trace... 2018/05/04 10:39:59 Splitting trace... 2018/05/04 10:39:59 Opening browser. Trace viewer is listening on http://127.0.0.1:51803
  14. @rakyll $ go get go.opencensus.io/trace import rt “runtime/trace” ctx, span

    := trace.StartSpan(ctx, “/messages”) defer span.End() rt.WithRegion(ctx, “foo”, func(ctx) { // Do something... })
  15. @rakyll Limitations • Execution tracer cannot do accounting for cross-goroutine

    operations automatically. • Exposition format is hard to parse if `go trace tool` is not used.