package main import ( "crypto/rand" "fmt" "math" "os" "strconv" "time" "edge-infra.dev/pkg/lib/fog" ) // use up memory for testing // from command line e.g. // MEMORYLOAD=3000 go run hack/sds/memoryload/main.go func main() { log := fog.New().WithName("memoryload") // Check if the user provided an argument for the size size := os.Getenv("MEMORYLOAD") if len(size) < 1 { err := fmt.Errorf("invalid arguments") log.Error(err, "please provide MEMORYLOAD as ENV variable in MB") return } // Convert the argument to an integer sizeInMB, err := strconv.Atoi(size) if err != nil { err := fmt.Errorf("invalid arguments") log.Error(err, "valid number of Mb not provided") return } // Calculate the size in bytes sizeInBytes := sizeInMB * 1024 * 1024 // Allocate memory data := make([]byte, sizeInBytes) log.Info("allocating memory", "size (bytes)", sizeInBytes) // Fill the allocated memory with random data stuff, err := rand.Read(data) if err != nil { log.Error(err, "unable to generated random data") return } log.Info("successfully filled memory", "bytes", stuff) // Prevent the program from exiting immediately time.Sleep(math.MaxInt64) }