Merge pull request #840 from filecoin-project/feat/bench-bps

bench: print bps speeds
This commit is contained in:
Łukasz Magiera 2019-12-10 21:21:13 +01:00 committed by GitHub
commit 7d5709f4e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 26 deletions

24
cli/utils.go Normal file
View File

@ -0,0 +1,24 @@
package cli
import (
"fmt"
"math/big"
"github.com/filecoin-project/lotus/chain/types"
)
var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}
func SizeStr(size types.BigInt) string {
r := new(big.Rat).SetInt(size.Int)
den := big.NewRat(1, 1024)
var i int
for f, _ := r.Float64(); f >= 1024 && 1 < len(Units); f, _ = r.Float64() {
i++
r = r.Mul(r, den)
}
f, _ := r.Float64()
return fmt.Sprintf("%.3f %s", f, Units[i])
}

View File

@ -7,12 +7,14 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"math/rand"
"os"
"path/filepath"
"time"
ffi "github.com/filecoin-project/filecoin-ffi"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log"
"github.com/mitchellh/go-homedir"
@ -21,6 +23,7 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/lib/sectorbuilder"
)
@ -315,7 +318,7 @@ func main() {
}
verifypost2 := time.Now()
benchout := BenchResults{
bo := BenchResults{
SectorSize: cfg.SectorSize,
SealingResults: sealTimings,
@ -327,7 +330,7 @@ func main() {
} // TODO: optionally write this as json to a file
if c.Bool("json-out") {
data, err := json.MarshalIndent(benchout, "", " ")
data, err := json.MarshalIndent(bo, "", " ")
if err != nil {
return err
}
@ -336,17 +339,17 @@ func main() {
} else {
fmt.Printf("results (%d)\n", sectorSize)
if robench == "" {
fmt.Printf("seal: addPiece: %s\n", benchout.SealingResults[0].AddPiece) // TODO: average across multiple sealings
fmt.Printf("seal: preCommit: %s\n", benchout.SealingResults[0].PreCommit)
fmt.Printf("seal: Commit: %s\n", benchout.SealingResults[0].Commit)
fmt.Printf("seal: Verify: %s\n", benchout.SealingResults[0].Verify)
fmt.Printf("unseal: %s\n", benchout.SealingResults[0].Unseal)
fmt.Printf("seal: addPiece: %s (%s)\n", bo.SealingResults[0].AddPiece, bps(bo.SectorSize, bo.SealingResults[0].AddPiece)) // TODO: average across multiple sealings
fmt.Printf("seal: preCommit: %s (%s)\n", bo.SealingResults[0].PreCommit, bps(bo.SectorSize, bo.SealingResults[0].PreCommit))
fmt.Printf("seal: commit: %s (%s)\n", bo.SealingResults[0].Commit, bps(bo.SectorSize, bo.SealingResults[0].Commit))
fmt.Printf("seal: verify: %s\n", bo.SealingResults[0].Verify)
fmt.Printf("unseal: %s (%s)\n", bo.SealingResults[0].Unseal, bps(bo.SectorSize, bo.SealingResults[0].Unseal))
}
fmt.Printf("generate candidates: %s\n", benchout.PostGenerateCandidates)
fmt.Printf("compute epost proof (cold): %s\n", benchout.PostEProofCold)
fmt.Printf("compute epost proof (hot): %s\n", benchout.PostEProofHot)
fmt.Printf("verify epost proof (cold): %s\n", benchout.VerifyEPostCold)
fmt.Printf("verify epost proof (hot): %s\n", benchout.VerifyEPostHot)
fmt.Printf("generate candidates: %s (%s)\n", bo.PostGenerateCandidates, bps(bo.SectorSize*uint64(len(bo.SealingResults)), bo.PostGenerateCandidates))
fmt.Printf("compute epost proof (cold): %s\n", bo.PostEProofCold)
fmt.Printf("compute epost proof (hot): %s\n", bo.PostEProofHot)
fmt.Printf("verify epost proof (cold): %s\n", bo.VerifyEPostCold)
fmt.Printf("verify epost proof (hot): %s\n", bo.VerifyEPostHot)
}
return nil
},
@ -357,3 +360,10 @@ func main() {
return
}
}
func bps(data uint64, d time.Duration) string {
bdata := new(big.Int).SetUint64(data)
bdata = bdata.Mul(bdata, big.NewInt(time.Second.Nanoseconds()))
bps := bdata.Div(bdata, big.NewInt(d.Nanoseconds()))
return lcli.SizeStr(types.BigInt{bps}) + "/s"
}

View File

@ -43,7 +43,7 @@ var infoCmd = &cli.Command{
return err
}
fmt.Printf("Sector Size: %s\n", sizeStr(types.NewInt(sizeByte)))
fmt.Printf("Sector Size: %s\n", lcli.SizeStr(types.NewInt(sizeByte)))
pow, err := api.StateMinerPower(ctx, maddr, nil)
if err != nil {
@ -51,7 +51,7 @@ var infoCmd = &cli.Command{
}
percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower)
fmt.Printf("Power: %s / %s (%0.4f%%)\n", sizeStr(pow.MinerPower), sizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000)
fmt.Printf("Power: %s / %s (%0.4f%%)\n", lcli.SizeStr(pow.MinerPower), lcli.SizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000)
// TODO: indicate whether the post worker is in use
wstat, err := nodeApi.WorkerStats(ctx)
@ -110,18 +110,6 @@ var infoCmd = &cli.Command{
},
}
var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}
func sizeStr(size types.BigInt) string {
size = types.BigMul(size, types.NewInt(100))
i := 0
for types.BigCmp(size, types.NewInt(102400)) >= 0 && i < len(Units)-1 {
size = types.BigDiv(size, types.NewInt(1024))
i++
}
return fmt.Sprintf("%s.%s %s", types.BigDiv(size, types.NewInt(100)), types.BigMod(size, types.NewInt(100)), Units[i])
}
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
sectors, err := napi.SectorsList(ctx)
if err != nil {