erigon-pulse/cmd/hack/scripts/parse_performance.go
Evgeny Danilenko e4e36c152e
Extract validating interface (#1120)
* interface

* generalize interface

* linters

* fix deadlock

* fix linters

* close goroutine

* fix

* debug

* id+ttl

* refactor downloader tests

* tests

* lru

* handle genesis, extract fake consensuses

* fix fake consensus

* test uncles, verify

* after a new master

* fmt

* fix close

* debug

* debug

* fix chain length

* remove test field

* use single account

* fix data race on closing channel

* remove postponed blocks queue

* miner test

* VerifyHeaderRequests

* fmt

* fmt

* fix data race

* handle validating errors

* simplify matchParents

* remove copy-paste

* move sort to constructor

* clean up

* debug for 10 parents

* debug

* debug

* batch responses

* batch requests

* works for many ancestors

* remove debug

* always Close an engine

* linters

* ancestors deduplication

* fix test

* reduce interface

* api

* clique

* green clique sync

* stable

* perpermance per second

* full sync

* linters

* gitignore

* deps

* fix panic after master merge

* init consensus

* clique tests

* fix tests

* fix tests

* clean up

* reuse snap

* store vefified snapshots

* optimize snapshots

* safe close

* cleanup loop

* after downloader

* downloader and consensus tests

* update tests

* hack.go

* clique flags

* fix cliuqe config

* review

* gitignore

* remove additional bucket

* blk/sec instead of blk/microsecond

* rename

* deps

* optimize

* debug

* test

* tests without extracted validation process

* same base performance as on master

* benchmark

* simplify ethash verification

* ethash

* ethash

* linters

* ethash

* master stats

* cleanup

* gomod

* linters

* tests

* better locks

* Fix

* Remove logging for verifyHeaders

* Verification speed in the logs

* Fix compile error

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-02-25 19:40:45 +00:00

137 lines
2.7 KiB
Go

package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"log"
"os"
"sort"
"strconv"
"time"
"gonum.org/v1/gonum/stat"
)
func main() {
pathVal := flag.String("path", "", "a path to a log file")
flag.Parse()
if pathVal == nil {
log.Fatal("a path is required")
return
}
path := *pathVal
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(f)
defer f.Close()
var (
prefix = []byte("Imported new block headers")
countPrefix = []byte("count=")
elapsedPrefix = []byte("elapsed=")
)
var r *row
var totalTime time.Duration
var totalCount int
blocksPerMs := make([]float64, 0, 2048)
for scanner.Scan() {
r = newRow(scanner.Bytes(), prefix, countPrefix, elapsedPrefix)
if r != nil {
blocksPerMs = append(blocksPerMs, r.blocksPerMs)
totalTime += r.elapsed
totalCount += r.count
}
}
sort.Float64s(blocksPerMs)
fmt.Println("total time", totalTime)
fmt.Println("blocks", totalCount)
if len(blocksPerMs) > 0 {
fmt.Printf("min %f blk/s\n", blocksPerMs[0])
fmt.Printf("max %f blk/s\n", blocksPerMs[len(blocksPerMs)-1])
}
fmt.Printf("mean %f blk/s\n", float64(totalCount)/totalTime.Seconds())
fmt.Printf("quantile blk/s:\n"+
"\t0.10 = %f\n\t0.25 = %f\n\t0.50 = %f\n\t0.75 = %f\n\t0.90 = %f\n\t0.95 = %f\n\t0.99 = %f\n",
stat.Quantile(0.10, stat.Empirical, blocksPerMs, nil),
stat.Quantile(0.25, stat.Empirical, blocksPerMs, nil),
stat.Quantile(0.50, stat.Empirical, blocksPerMs, nil),
stat.Quantile(0.75, stat.Empirical, blocksPerMs, nil),
stat.Quantile(0.90, stat.Empirical, blocksPerMs, nil),
stat.Quantile(0.95, stat.Empirical, blocksPerMs, nil),
stat.Quantile(0.99, stat.Empirical, blocksPerMs, nil))
}
type row struct {
count int
elapsed time.Duration
blocksPerMs float64
}
func newRow(s, hasPrefix, count, elapsed []byte) *row {
if !bytes.Contains(s, hasPrefix) {
return nil
}
idxFrom := bytes.Index(s, elapsed)
if idxFrom == -1 {
return nil
}
idxFrom += len(elapsed)
for _, c := range s[idxFrom:] {
if c != ' ' {
break
}
idxFrom++
}
idxTo := bytes.IndexByte(s[idxFrom:], ' ')
if idxTo == -1 {
return nil
}
duration, err := time.ParseDuration(string(s[idxFrom : idxFrom+idxTo]))
if err != nil {
fmt.Println("err", err)
return nil
}
r := &row{}
r.elapsed = duration
idxFrom = bytes.Index(s, count)
if idxFrom == -1 {
return nil
}
idxFrom += len(count)
for _, c := range s[idxFrom:] {
if c != ' ' {
break
}
idxFrom++
}
idxTo = bytes.IndexByte(s[idxFrom:], ' ')
if idxTo == -1 {
return nil
}
countValue, err := strconv.Atoi(string(s[idxFrom : idxFrom+idxTo]))
if err != nil {
fmt.Println("err", err)
return nil
}
r.count = countValue
r.blocksPerMs = float64(r.count) / r.elapsed.Seconds()
return r
}