Skip to content

Commit

Permalink
cadency
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-ferreira-encora committed Nov 7, 2024
1 parent d257947 commit 514d375
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
9 changes: 7 additions & 2 deletions cmd/tradeclient/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ type LoadTestConfig struct {
TargetCompID string
}

// RunLoadTest sends orders based on the provided configuration.
// sends orders based on the provided configuration.
func RunLoadTest(cfg LoadTestConfig) {
var wg sync.WaitGroup

// Launch goroutines to send orders at the specified rate
// send orders at the specified rate
for i := 0; i < cfg.TotalOrders; i++ {
wg.Add(1)
go func(orderID int) {
Expand All @@ -34,4 +34,9 @@ func RunLoadTest(cfg LoadTestConfig) {
// Delay to maintain order rate
time.Sleep(time.Second / time.Duration(cfg.OrdersPerSecond))
}

// Wait for all goroutines to complete
wg.Wait()

fmt.Println("Load test finished, all orders have been processed.")
}
52 changes: 47 additions & 5 deletions cmd/tradeclient/tradeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path"
"strconv"
"time"

"github.com/quickfixgo/examples/cmd/readmetrics"
"github.com/quickfixgo/examples/cmd/tradeclient/internal"
Expand Down Expand Up @@ -233,10 +234,8 @@ Loop:
err = internal.QueryMarketDataRequest("CUST2_Marketdata", "ANCHORAGE")

case "4":
var ordersPerSecond int
var totalOrders int

// Prompt the user for orders per second
var ordersPerSecond int
fmt.Print("Enter orders per second: ")
_, err := fmt.Scanf("%d", &ordersPerSecond)
if err != nil {
Expand All @@ -245,13 +244,23 @@ Loop:
}

// Prompt the user for total number of orders
var totalOrders int
fmt.Print("Enter total number of orders: ")
_, err = fmt.Scanf("%d", &totalOrders)
if err != nil {
utils.PrintBad("Invalid input for total orders")
break
}

// Ask if the user wants to set a cadency
var setCadency string
fmt.Print("Do you want to set a cadency for the load test? (yes/no): ")
_, err = fmt.Scanf("%s", &setCadency)
if err != nil {
utils.PrintBad("Invalid input for cadency choice")
break
}

// Create load test configuration
loadTestConfig := loadtest.LoadTestConfig{
OrdersPerSecond: ordersPerSecond,
Expand All @@ -260,8 +269,41 @@ Loop:
TargetCompID: "ANCHORAGE",
}

// Run the load test
loadtest.RunLoadTest(loadTestConfig)
if setCadency == "yes" {
// Prompt the user for cadency
var cadencyInput string
fmt.Print("Enter the cadency (e.g., '10m' for 10 minutes, '1d' for every day, '3d' for every 3 days): ")
_, err = fmt.Scanf("%s", &cadencyInput)
if err != nil {
utils.PrintBad("Invalid input for cadency")
break
}

// Parse the cadency input into a time.Duration
interval, err := time.ParseDuration(cadencyInput)
if err != nil {
utils.PrintBad("Invalid cadency format")
break
}

// Run the load test at the specified interval
fmt.Printf("Starting load test every %v...\n", interval)

// Loop to run the load test at the specified interval
for {
// Run the load test
loadtest.RunLoadTest(loadTestConfig)

// Wait for the next interval
fmt.Printf("Waiting for next load test after %v...\n", interval)
time.Sleep(interval)
}
} else if setCadency == "no" {
// Run once without cadency
loadtest.RunLoadTest(loadTestConfig)
} else {
utils.PrintBad("Invalid input for cadency choice")
}

case "5":
// Call readmetrics after the load test
Expand Down

0 comments on commit 514d375

Please sign in to comment.