Skip to content

Commit

Permalink
feat: array of piece count / blocks per piece (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Apr 4, 2023
1 parent f2eeb12 commit 91fee5b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
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

0 comments on commit 91fee5b

Please sign in to comment.