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

Performance Analysis 101

Performance Analysis 101

Palestra sobre analise de performance de aplicações python em ambiente linux.

Tarsis Azevedo

October 16, 2016
Tweet

More Decks by Tarsis Azevedo

Other Decks in Programming

Transcript

  1. func CheckUserAccess(teamNames []string, u *User) bool { q := bson.M{"_id":

    bson.M{"$in": teamNames}} var teams []Team conn, err := db.Conn() if err != nil { log.Errorf("Failed to connect to the database: %s", err) return false } defer conn.Close() conn.Teams().Find(q).All(&teams) var wg sync.WaitGroup found := make(chan bool, len(teams)+1) for _, team := range teams { wg.Add(1) go func(t Team) { if t.ContainsUser(u) { found <- true } wg.Done() }(team) } go func() { wg.Wait() found <- false }() return <-found } https://github.com/tsuru/tsuru/blob/c54c2c073aa9bf1db888a0bed45ffafbf62cbf18/auth/team.go
  2. var wg sync.WaitGroup found := make(chan bool, len(teams)+1) for _,

    team := range teams { wg.Add(1) go func(t Team) { if t.ContainsUser(u) { found <- true } wg.Done() }(team) } go func() { wg.Wait() found <- false }() return <-found
  3. func CheckUserAccess(teamNames []string, u *User) bool { q := bson.M{"_id":

    bson.M{"$in": teamNames}} var teams []Team conn, err := db.Conn() if err != nil { log.Errorf("Failed to connect to the database: %s", err) return false } defer conn.Close() conn.Teams().Find(q).All(&teams) for _, team := range teams { if team.ContainsUser(u) { return true } } return false } https://github.com/tsuru/tsuru/blob/fafa683c5cc1e736df03116b11fc5868c54e30d5/auth/team.go#L138
  4. //go:generate bash -c "ragel -Z -G2 -o parser.go parser.rl &&

    gofmt -s -w parser.go && gofmt -s -w parser.go" %%{ machine lineparser; write data; }%% func parseLogLine(data []byte) ([][]byte, bool, bool) { parts := make([][]byte, 8) start := 0 pIdx := -1 cs, p, pe := 0, 0, len(data) eof := pe withMsg := false withPID := false %%{ action di { pIdx++; start = p } action dd { parts[pIdx] = data[start:p] } action msgok { withMsg = true } action withpid { withPID = true } main := '<' ( digit )+ >di %dd '>' space* ( any - space )+ >di %dd space+ ( ( digit+ space digit+ ':' digit+ ':' digit+ ) >di %dd space+ )? ( any - space )+ >di %dd space+ ( any - space - '[' - ']' )+ >di %dd ('[' ( digit )+ >di %dd >withpid ']')? ':' space+ ( any )+ >di %dd >msgok; write init; write exec; }%% return parts, withMsg, withPID } https://github.com/tsuru/bs/blob/master/log/parser.rl
  5. Resumindo Não faça otimizações precocemente;
 
 Estresse sua aplicação localmente;


    
 Defina o problema primeiro; Busque métricas melhores sempre.
  6. • System Performance book - Brendon Gregg • Talk: Linux

    Performance Tools • Julia Evans’ blog: tcpdump, tcpdump 2 • Unix/Linux Handbook • Diving into the Wreck: a postmortem look at real-works performance • Ragel • Profiling Go program • perf • FlameGraph • CPU Flame Graph Referências