FNIHCS
Finding Needles In Haystacks, and Chaotic Systems!
3 December 2020
Emmanuel T Odeke
Orijtech, Inc.
Emmanuel T Odeke
Orijtech, Inc.





Manish's tweet https://twitter.com/manishrjain/status/1090041366380302336




"contentType":null
// Return anomalous spans. µPlus3σ := st.mean + 3*st.stddev µMinus3σ := st.mean - 3*st.stddev above3Sigma := make([]*spanDetails, 0, len(sds)) below3Sigma := make([]*spanDetails, 0, len(sds)) nonInteresting := make([]*spanDetails, 0, len(sds)) for _, sd := range sds { if sd.latencyMs >= µPlus3σ { above3Sigma = append(above3Sigma, sd) } else if sd.latencyMs <= µMinus3σ { below3Sigma = append(below3Sigma, sd) } else { nonInteresting = append(nonInteresting, sd) } }
package main import "runtime/pprof" func periodicallyCPUProfile(ctx context.Context, w io.Writer) error { for { if err := pprof.StartCPUProfile(w); err != nil { panic(err) } select { case <-ctx.Done(): return ctx.Err() case <-time.After(profilingPeriod): pprof.StopCPUProfile() } <-time.After(profilingPausePeriod) } } func main() { go periodicallyCPUProfile(ctx, w) defer cancel() // The rest of the logic goes down below... }
package main import _ "net/http/pprof" func main() { go func() { log.Println(http.ListenAndServe(":3338", nil)) }() // Rest of your logic goes here }
and then fetch a CPU profile
go tool pprof http://localhost:3338/debug/pprof/profile?seconds=30
32

package main import "runtime/pprof" func periodicallyMemoryProfile(ctx context.Context, w io.Writer) error { for { select { case <-ctx.Done(): return ctx.Err() case <-time.After(profilingPeriod): if err := pprof.WriteHeapProfile(w); err != nil { panic(err) } } <-time.After(profilingPausePeriod) } } func main() { go periodicallyMemoryProfile(ctx, w) defer cancel() // The rest of the logic goes down below... }
package main import _ "net/http/pprof" func main() { go func() { log.Println(http.ListenAndServe(":3338", nil)) }() // Rest of your logic goes here }
and then fetch a CPU profile
go tool pprof http://localhost:3338/debug/pprof/heap?seconds=30
35

Emmanuel T Odeke
Orijtech, Inc.
Observability, and infrastructure for high performance systems, and the cloud!