Skip to content

Commit

Permalink
Adds urfave/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
pschork committed Jun 7, 2024
1 parent 07d1fb9 commit ca4684c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tools/batchgen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ clean:
rm -rf ./bin

run: build
./bin/batchgen 1000 10 localhost:32005
./bin/batchgen --host localhost:32005

24 changes: 10 additions & 14 deletions tools/batchgen/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os"
"strconv"

commonpb "github.com/Layr-Labs/eigenda/api/grpc/common"
pb "github.com/Layr-Labs/eigenda/api/grpc/node"
Expand Down Expand Up @@ -38,32 +37,26 @@ func main() {
app.Flags = flags.Flags
app.Action = batchGeneratorMain
if err := app.Run(os.Args); err != nil {
log.Fatalf("runtime failure: %v", err)
log.Fatal(err)
}
}

func batchGeneratorMain() {
threads, err := strconv.Atoi(os.Args[2])
if err != nil {
log.Fatalf("failed to convert threads to int:", err)
}

factor, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatalf("failed to convert batch scaling factor to int:", err)
}
func batchGeneratorMain(ctx *cli.Context) {
threads := int(ctx.GlobalUint(flags.NumThreadsFlag.Name))
factor := int(ctx.GlobalUint(flags.ScalingFactorFlag.Name))
hosts := ctx.GlobalStringSlice(flags.HostsFlag.Name)

hosts := os.Args[3:]
results := make(chan *pb.StoreChunksReply, len(hosts))
errors := make(chan error, len(hosts))

req, _, _, _, _ := makeStoreChunksRequest(100, 10, factor)
reqSizeMB := float64(proto.Size(req)) / 1024.0 / 1024.0
totalSizeMB := reqSizeMB * float64(threads) * float64(len(hosts))
log.Println("request size", reqSizeMB, "total data sent", totalSizeMB, "MB")

for _, host := range hosts {
log.Printf("host: %v", host)
for i := 0; i < threads; i++ {
log.Printf("i: %v", i)
go func(host string, i int) {
conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
Expand Down Expand Up @@ -93,6 +86,9 @@ func batchGeneratorMain() {
log.Println("ERR", err)
}
}

log.Println("request size", reqSizeMB, "total data sent", totalSizeMB, "MB")
os.Exit(0)
}

func makeStoreChunksRequest(quorumThreshold, adversaryThreshold uint8, factor int) (*pb.StoreChunksRequest, [32]byte, [32]byte, []*core.BlobHeader, []*pb.BlobHeader) {
Expand Down
23 changes: 15 additions & 8 deletions tools/batchgen/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,43 @@ import (
)

const (
FlagPrefix = "batchgen"
FlagPrefix = ""
envPrefix = "BATCHGEN"
)

var (
/* Required Flags */

NumThreadsFlag = cli.UintFlag{
Name: "host-threads",
Name: common.PrefixFlag(FlagPrefix, "threads"),
Usage: "Number of host threads in parallel",
Required: false,
Value: 1,
EnvVar: "HOST_THREADS",
EnvVar: common.PrefixEnvVar(envPrefix, "HOST_THREADS"),
}
ScalingFactorFlag = cli.UintFlag{
Name: "scaling-factor",
Name: common.PrefixFlag(FlagPrefix, "scaling-factor"),
Usage: "Scaling factor applied to default batch size",
Required: false,
Value: 10,
EnvVar: "SCALING_FACTOR",
Value: 100,
EnvVar: common.PrefixEnvVar(envPrefix, "SCALING_FACTOR"),
}
HostsFlag = cli.StringSliceFlag{
Name: common.PrefixFlag(FlagPrefix, "host"),
Usage: "host:port",
Required: true,
}
)

var requiredFlags = []cli.Flag{
HostsFlag,
}

var optionalFlags = []cli.Flag{
NumThreadsFlag,
ScalingFactorFlag,
}

var optionalFlags = []cli.Flag{}

// Flags contains the list of configuration options available to the binary.
var Flags []cli.Flag

Expand Down

0 comments on commit ca4684c

Please sign in to comment.