Skip to content

Commit

Permalink
improve: improving scripts.
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro committed Aug 29, 2023
1 parent c40b8dd commit e5faf3e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 83 deletions.
2 changes: 1 addition & 1 deletion test/benchmarks/sequencer/common/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func PrintSummary(
fmt.Printf("- Executor Time Percentage from Total: %.2f%%\n\n", (processingTimeExecutor/processingTimeSequencer)*oneHundred)
fmt.Println("Metrics:")
fmt.Printf("- Transactions per Second: %.2f\n", float64(totalTxs)/processingTimeSequencer)
fmt.Printf("-- the rest of the metrics are only for predefined transactions - excluding the random transactions --\n")
fmt.Printf("[the rest of the metrics are only for predefined transactions - excluding the random transactions]\n")
fmt.Printf("- Gas per Second: %.2f\n", float64(totalGas)/processingTimeSequencer)
fmt.Printf("- Total Gas Used: %d\n", totalGas)
fmt.Printf("- Average Gas Used per Transaction: %d\n\n", totalGas/totalTxs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
package main

import (
"flag"
"fmt"

"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/metrics"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/scripts/environment"

"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/metrics"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/params"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/transactions"
erc20transfers "github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/e2e/erc20-transfers"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/scripts/environment"
)

func main() {
func ExecuteERC20Transfers(numOps uint64) uint64 {
var (
err error
)

numOps := flag.Uint64("num-ops", 200, "The number of operations to run. Default is 200.")
flag.Parse()

if numOps == nil {
panic("numOps is nil")
}

pl, l2Client, auth := environment.Init()
initialCount, err := pl.CountTransactionsByStatus(params.Ctx, pool.TxStatusSelected)
if err != nil {
panic(err)
}

erc20SC, err := erc20transfers.DeployERC20Contract(l2Client, params.Ctx, auth)

allTxs, err := transactions.SendAndWait(
auth,
l2Client,
pl.GetTxsByStatus,
*numOps,
numOps,
erc20SC,
nil,
erc20transfers.TxSender,
Expand All @@ -47,11 +35,12 @@ func main() {
}

// Wait for Txs to be selected
err = transactions.WaitStatusSelected(pl.CountTransactionsByStatus, initialCount, *numOps)
err = transactions.WaitStatusSelected(pl.CountTransactionsByStatus, initialCount, numOps)
if err != nil {
panic(err)
}

totalGas := metrics.GetTotalGasUsedFromTxs(l2Client, allTxs)
fmt.Println("Total Gas: ", totalGas)

return totalGas
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"flag"
"fmt"

"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/metrics"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/params"
Expand All @@ -12,15 +9,10 @@ import (
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/scripts/environment"
)

func main() {
func ExecuteEthTransfers(numOps uint64) uint64 {
var (
err error
)
numOps := flag.Uint64("num-ops", 200, "The number of operations to run. Default is 200.")
flag.Parse()
if numOps == nil {
panic("numOps is nil")
}

pl, l2Client, auth := environment.Init()
initialCount, err := pl.CountTransactionsByStatus(params.Ctx, pool.TxStatusSelected)
Expand All @@ -32,7 +24,7 @@ func main() {
auth,
l2Client,
pl.GetTxsByStatus,
*numOps,
numOps,
nil,
nil,
ethtransfers.TxSender,
Expand All @@ -42,11 +34,12 @@ func main() {
}

// Wait for Txs to be selected
err = transactions.WaitStatusSelected(pl.CountTransactionsByStatus, initialCount, *numOps)
err = transactions.WaitStatusSelected(pl.CountTransactionsByStatus, initialCount, numOps)
if err != nil {
panic(err)
}

totalGas := metrics.GetTotalGasUsedFromTxs(l2Client, allTxs)
fmt.Println("Total Gas: ", totalGas)

return totalGas
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
package main

import (
"flag"
"fmt"
"time"

"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/scripts/environment"

"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/params"

"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/metrics"

"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/params"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/transactions"
uniswaptransfers "github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/e2e/uniswap-transfers"
"github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/scripts/environment"
uniswap "github.com/0xPolygonHermez/zkevm-node/test/scripts/uniswap/pkg"
)

func main() {
func ExecuteUniswapTransfers(numOps uint64) uint64 {
var (
err error
)
numOps := flag.Uint64("num-ops", 200, "The number of operations to run. Default is 200.")
flag.Parse()
if numOps == nil {
panic("numOps is nil")
}

pl, l2Client, auth := environment.Init()
initialCount, err := pl.CountTransactionsByStatus(params.Ctx, pool.TxStatusSelected)
if err != nil {
Expand All @@ -40,7 +31,7 @@ func main() {
auth,
l2Client,
pl.GetTxsByStatus,
*numOps,
numOps,
nil,
&deployments,
uniswaptransfers.TxSender,
Expand All @@ -50,12 +41,13 @@ func main() {
}

// Wait for Txs to be selected
err = transactions.WaitStatusSelected(pl.CountTransactionsByStatus, initialCount, *numOps)
err = transactions.WaitStatusSelected(pl.CountTransactionsByStatus, initialCount, numOps)
if err != nil {
panic(err)
}

metrics.PrintUniswapDeployments(elapsedTimeForDeployments, deploymentTxsCount)
totalGas := metrics.GetTotalGasUsedFromTxs(l2Client, allTxs)
fmt.Println("Total Gas: ", totalGas)

return totalGas
}
48 changes: 12 additions & 36 deletions test/benchmarks/sequencer/scripts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func main() {
// Command line flags
tType := flag.String("type", "", "The type of transactions to test: erc20, uniswap, or eth.")
sequencerIP := flag.String("sequencer-ip", "", "The IP address of the sequencer.")
numOps := flag.Int("num-ops", 200, "The number of operations to run. Default is 200.")
numOps := flag.Uint64("num-ops", 200, "The number of operations to run. Default is 200.")
help := flag.Bool("help", false, "Display help message")
flag.Parse()

if *help {
fmt.Println("Usage: go run main.go --type TRANSACTIONS_TYPE --sequencer-ip SEQUENCER_IP [--num-ops NUMBER_OF_OPERATIONS]")
fmt.Println("Usage: go run exec_erc20_transfers.go --type TRANSACTIONS_TYPE --sequencer-ip SEQUENCER_IP [--num-ops NUMBER_OF_OPERATIONS]")
flag.PrintDefaults()
return
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func main() {
}
defer killSSHProcess(err)

// Execute wget to get metrics from the BASTION HOST
// ExecuteERC20Transfers wget to get metrics from the BASTION HOST
fmt.Println("Fetching start metrics...")
fmt.Println("--------------------------")
output, err := runCmd("ssh", "ubuntu@"+os.Getenv("BASTION_HOST"), "wget", "-qO-", "http://"+*sequencerIP+":9091/metrics")
Expand All @@ -91,38 +91,20 @@ func main() {
panic(fmt.Sprintf("Failed to write start metrics to file: %v", err))
}

// Run the Go script depending on the type argument
var goScript string
// Run transfers script
fmt.Println("Running transfers script...")
fmt.Println("---------------------------")
var totalGas uint64
switch *tType {
case "erc20":
goScript = "erc20-transfers"
totalGas = ExecuteERC20Transfers(*numOps)
case "uniswap":
goScript = "uniswap-transfers"
totalGas = ExecuteUniswapTransfers(*numOps)
case "eth":
goScript = "eth-transfers"
}

// Run transfers script
fmt.Println("Running transfers script...")
fmt.Println("---------------------------")
lastLine, err := runCmdRealTime("go", "run", "./"+goScript+"/main.go", "--num-ops", strconv.Itoa(*numOps))
if err != nil {
panic(fmt.Sprintf("Failed to run Go script for %s transactions: %v", *tType, err))
}

// Extract Total Gas
fmt.Println("Extracting Total Gas...")
fmt.Println("-----------------------")
var totalGas string
if strings.Contains(lastLine, "Total Gas") {
parts := strings.Split(lastLine, " ")
totalGas = parts[len(parts)-1]
}
if totalGas == "" {
fmt.Println("Warning: Failed to extract Total Gas from Go script output.")
totalGas = ExecuteEthTransfers(*numOps)
}

// Execute wget to get metrics from the BASTION HOST
// ExecuteERC20Transfers wget to get metrics from the BASTION HOST
fmt.Println("Fetching end metrics...")
fmt.Println("------------------------")
output, err = runCmd("ssh", "ubuntu@"+os.Getenv("BASTION_HOST"), "wget", "-qO-", "http://"+*sequencerIP+":9091/metrics")
Expand All @@ -134,16 +116,10 @@ func main() {
panic(fmt.Sprintf("Failed to write end metrics to file: %v", err))
}

// Run the Go script that calculates the metrics and prints the results
totalGasInt, err := strconv.ParseUint(totalGas, 10, 64)
if err != nil {
fmt.Printf("Failed to convert totalGas to int: %v\n", err)
}

// Calc and Print Results
fmt.Println("Calculating and printing results...")
fmt.Printf("------------------------------------\n\n")
calculateAndPrintResults(*tType, totalGasInt, uint64(*numOps))
calculateAndPrintResults(*tType, totalGas, *numOps)

fmt.Println("Done!")
}
Expand Down

0 comments on commit e5faf3e

Please sign in to comment.