Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array of piece count / blocks per piece #1314

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions extern/boostd-data/bench/common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package main

import "github.com/urfave/cli/v2"
import (
"github.com/urfave/cli/v2"
"strconv"
"strings"
)

var commonFlags = []cli.Flag{
&cli.IntFlag{
Name: "piece-add-parallelism",
Value: 2,
},
&cli.StringSliceFlag{
Name: "pieces",
Usage: "Array of piece count / blocks per piece in the form '<piece count>x<blocks per piece>' (eg '10x128')",
Value: cli.NewStringSlice("30x1024"),
},
&cli.IntFlag{
Name: "piece-count",
Value: 30,
Expand All @@ -33,11 +42,36 @@ var commonFlags = []cli.Flag{
},
}

const piecesUsageErr = "pieces parameter must be of the form <piece count>x<blocks per piece>"

func runOptsFromCctx(cctx *cli.Context) runOpts {
pieces := cctx.StringSlice("pieces")
addPiecesSpecs := make([]addPiecesSpec, 0, len(pieces))
for _, pc := range pieces {
countBlocks := strings.Split(pc, "x")
if len(countBlocks) != 2 {
panic(piecesUsageErr)
}

pieceCount, err := strconv.Atoi(countBlocks[0])
if err != nil {
panic(piecesUsageErr)
}

blocksPerPiece, err := strconv.Atoi(countBlocks[1])
if err != nil {
panic(piecesUsageErr)
}

addPiecesSpecs = append(addPiecesSpecs, addPiecesSpec{
pieceCount: pieceCount,
blocksPerPiece: blocksPerPiece,
})
}

return runOpts{
addPiecesSpecs: addPiecesSpecs,
pieceParallelism: cctx.Int("piece-add-parallelism"),
blocksPerPiece: cctx.Int("blocks-per-piece"),
pieceCount: cctx.Int("piece-count"),
bitswapFetchCount: cctx.Int("bs-fetch-count"),
bitswapFetchParallelism: cctx.Int("bs-fetch-parallelism"),
graphsyncFetchCount: cctx.Int("gs-fetch-count"),
Expand Down
22 changes: 17 additions & 5 deletions extern/boostd-data/bench/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ type BenchDB interface {
GetIterableIndex(ctx context.Context, pieceCid cid.Cid) (carindex.IterableIndex, error)
}

type addPiecesSpec struct {
pieceCount int
blocksPerPiece int
}

type runOpts struct {
addPiecesSpecs []addPiecesSpec
pieceParallelism int
blocksPerPiece int
pieceCount int
bitswapFetchCount int
bitswapFetchParallelism int
graphsyncFetchCount int
Expand All @@ -60,8 +64,10 @@ func run(ctx context.Context, db BenchDB, opts runOpts) error {
}()

// Add sample data to the database
if err := addPieces(ctx, db, opts.pieceParallelism, opts.pieceCount, opts.blocksPerPiece); err != nil {
return err
for _, pc := range opts.addPiecesSpecs {
if err := addPieces(ctx, db, opts.pieceParallelism, pc.pieceCount, pc.blocksPerPiece); err != nil {
return err
}
}

// Run bitswap fetch simulation
Expand Down Expand Up @@ -89,7 +95,13 @@ func loadCmd(createDB func(context.Context, string) (BenchDB, error)) *cli.Comma
}

opts := runOptsFromCctx(cctx)
return addPieces(ctx, db, opts.pieceParallelism, opts.pieceCount, opts.blocksPerPiece)
for _, pc := range opts.addPiecesSpecs {
err = addPieces(ctx, db, opts.pieceParallelism, pc.pieceCount, pc.blocksPerPiece)
if err != nil {
return err
}
}
return nil
},
}
}
Expand Down