diff --git a/README.md b/README.md index ba044ff..d7f0b11 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,14 @@ This repo contains a Go program to help you benchmark and compare Fiber vs. Bloxroute transaction streams. ## Requirements -* Golang: https://go.dev/doc/install + +- Golang: https://go.dev/doc/install ## Usage + Options: -``` + +```text NAME: fiber-benchmark - Benchmark Fiber against other data sources @@ -20,21 +23,26 @@ COMMANDS: help, h Shows a list of commands or help for one command GLOBAL OPTIONS: - --fiber-endpoint value Fiber API endpoint - --fiber-key value Fiber API key - --blxr-endpoint value Bloxroute API endpoint - --blxr-key value Bloxroute API key - --interval value Duration of each interval (default: 0s) - --interval-count value Number of intervals to run (default: 1) - --log-file value File to save detailed logs - --help, -h show help + --fiber-endpoint value Fiber API endpoint + --fiber-key value Fiber API key + --blxr-endpoint value Bloxroute API endpoint + --blxr-key value Bloxroute API key + --interval value Duration of each interval (default: 0s) + --interval-count value Number of intervals to run (default: 1) + --log-file value File to save detailed logs + --fiber-only Only benchmark between two Fiber endpoints (default: false) + --help, -h show help ``` + ### Transactions + Example: + ```bash go run . --fiber-endpoint $FIBER_ENDPOINT --fiber-key $FIBER_KEY \ --blxr-endpoint $BLXR_WS_ENDPOINT --blxr-key $BLXR_KEY --interval 20s --log-file benchmarks.csv transactions ``` ### Blocks -WIP \ No newline at end of file + +WIP diff --git a/main.go b/main.go index c3949b4..b21602e 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ type config struct { logFile string sink string benchmarkID string + fiberOnly bool clickhouse clickhouse.ClickhouseConfig } @@ -176,6 +177,12 @@ func main() { Usage: "File to save detailed logs in case of file sink", Destination: &config.logFile, }, + &cli.BoolFlag{ + Name: "fiber-only", + Usage: "Benchmark two separate Fiber endpoints between each other", + Value: false, + Destination: &config.fiberOnly, + }, &cli.StringFlag{ Name: "sink", Usage: "Output sink. Options: 'clickhouse', 'svg', 'stdout', 'none'. Default: 'none'", diff --git a/transactions.go b/transactions.go index 03c0abe..a603326 100644 --- a/transactions.go +++ b/transactions.go @@ -36,17 +36,34 @@ func runTransactionBenchmark(config *config) error { logger.Fatal().Err(err).Msg("Invalid config") } - fiberSource := fiber.NewFiberSource(config.fiberEndpoints, config.fiberKey) - if err := fiberSource.Connect(); err != nil { - return err - } - + var fiberSource *fiber.FiberSource var otherSource TransactionSource var otherSourceName string - if config.blxrEndpoint != "" && config.blxrKey != "" { - otherSource = bloxroute.NewBloxrouteSource(config.blxrEndpoint, config.blxrKey) - otherSourceName = "bloxroute" + if config.fiberOnly { + firstEndpoint := config.fiberEndpoints[0] + fiberSource = fiber.NewFiberSource([]string{firstEndpoint}, config.fiberKey) + if err := fiberSource.Connect(); err != nil { + return err + } + + otherSourceName = "fiber-2" + secondEndpoint := config.fiberEndpoints[1] + otherFiberSource := fiber.NewFiberSource([]string{secondEndpoint}, config.fiberKey) + if err := otherFiberSource.Connect(); err != nil { + return err + } + otherSource = otherFiberSource + } else { + fiberSource = fiber.NewFiberSource(config.fiberEndpoints, config.fiberKey) + if err := fiberSource.Connect(); err != nil { + return err + } + + if config.blxrEndpoint != "" && config.blxrKey != "" { + otherSource = bloxroute.NewBloxrouteSource(config.blxrEndpoint, config.blxrKey) + otherSourceName = "bloxroute" + } } sink, err := setupSink(config, sinks.Transactions)