From f70b97cbb0f73fe59bf9813d215a542429fe30e8 Mon Sep 17 00:00:00 2001 From: clphan Date: Sat, 13 May 2023 20:11:02 +0700 Subject: [PATCH] Update app-loadtest for testing concurrent --- app-loadtest/app-loadtest-test.go | 28 ++++++++++++++++++ app-loadtest/app-loadtest.go | 35 +++++++++++++---------- app-loadtest/deploy/02-deployment.yaml | 8 +----- app-simulate/app-simulate.go | 36 ++++++++++++------------ app-simulate/deploy/02-deployment.yaml | 2 +- system/ops/istio-monitor/prometheus.yaml | 2 +- 6 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 app-loadtest/app-loadtest-test.go diff --git a/app-loadtest/app-loadtest-test.go b/app-loadtest/app-loadtest-test.go new file mode 100644 index 0000000..db0de04 --- /dev/null +++ b/app-loadtest/app-loadtest-test.go @@ -0,0 +1,28 @@ +package main +import ( + "fmt" + "sync" + // "time" +) + + +func main() { + for { + // Start sending requests in goroutines + var wg sync.WaitGroup + numRequests := 10 + wg.Add(numRequests) + + for i := 0; i < numRequests; i++ { + go sendRequest(&wg, i) + // time.Sleep(time.Second) + } + wg.Wait() + } +} + + +func sendRequest(wg *sync.WaitGroup, counter int) { + defer wg.Done() + fmt.Println("counter: ", counter) +} diff --git a/app-loadtest/app-loadtest.go b/app-loadtest/app-loadtest.go index 790583f..6e4986b 100644 --- a/app-loadtest/app-loadtest.go +++ b/app-loadtest/app-loadtest.go @@ -79,7 +79,7 @@ func init() { func getSSMParam(parameterName string) (string, error){ // Create an input object for the GetParameter API input := &ssm.GetParameterInput{ - Name: aws.String(parameterName), + Name: aws.String(parameterName), WithDecryption: aws.Bool(true), } result, err := ssmClient.GetParameter(input) @@ -111,24 +111,28 @@ func main() { } queryParams := url.Values{} queryParams.Set("num_bytes", appLoadtestBytesParamName) - requestURL := fmt.Sprintf("http://app-simulate.app-simulate.svc.cluster.local:5000/bytes?%s", queryParams.Encode()) + // requestURL := fmt.Sprintf("http://app-simulate.app-simulate.svc.cluster.local:5000/bytes?%s", queryParams.Encode()) + requestURL := fmt.Sprintf("http://localhost:5000/bytes?%s", queryParams.Encode()) duration := 60*time.Second interval := duration/time.Duration(numRequests) - startTime := time.Now() - // Start sending requests in goroutines - var wg sync.WaitGroup - wg.Add(numRequests) - - for i := 0; i < numRequests; i++ { - go sendRequest(&wg, requestURL) - time.Sleep(interval) + for { + startTime := time.Now() + // Start sending requests in goroutines + var wg sync.WaitGroup + wg.Add(numRequests) + + for i := 0; i < numRequests; i++ { + go sendRequest(&wg, requestURL) + time.Sleep(interval) + } + endTime := time.Now() + loadtestDuration := endTime.Sub(startTime) + loadtestSeconds := loadtestDuration.Seconds() + appLoadtestResponseDurationAll.Set(loadtestSeconds) + wg.Wait() } - endTime := time.Now() - loadtestDuration := endTime.Sub(startTime) - loadtestSeconds := loadtestDuration.Seconds() - appLoadtestResponseDurationAll.Set(loadtestSeconds) - wg.Wait() + } @@ -152,6 +156,7 @@ func sendRequest(wg *sync.WaitGroup, requestURL string) { endTimeEachRequest := time.Now() loadtestDurationEachRequest := endTimeEachRequest.Sub(startTimeEachRequest) loadtestSecondsEachRequest := loadtestDurationEachRequest.Seconds() + fmt.Println("loadtestSecondsEachRequest ",loadtestSecondsEachRequest) responseDurationEachRequest.Set(loadtestSecondsEachRequest) // Increment the requests counter diff --git a/app-loadtest/deploy/02-deployment.yaml b/app-loadtest/deploy/02-deployment.yaml index c2e8d7f..f94376d 100644 --- a/app-loadtest/deploy/02-deployment.yaml +++ b/app-loadtest/deploy/02-deployment.yaml @@ -25,7 +25,7 @@ spec: spec: containers: - name: app-loadtest - image: 832438989008.dkr.ecr.ap-southeast-1.amazonaws.com/app-loadtest@sha256:c828ab9143608ba9b0839cc2740bd2ce9ed2968c1c4e13f7b7d4aae8892e400e + image: 832438989008.dkr.ecr.ap-southeast-1.amazonaws.com/app-loadtest@sha256:fe22b101168b50d202579c9b558a8e8f0a5dcbacfc21a3f5e9fb28fa5062c60c ports: - name: prometheus containerPort: 8000 @@ -36,9 +36,3 @@ spec: - /app/healthy initialDelaySeconds: 5 periodSeconds: 5 - # readinessProbe: - # httpGet: - # path: /healthz/ready - # port: 5000 - # initialDelaySeconds: 5 - # periodSeconds: 5 diff --git a/app-simulate/app-simulate.go b/app-simulate/app-simulate.go index 62e86b1..1109879 100644 --- a/app-simulate/app-simulate.go +++ b/app-simulate/app-simulate.go @@ -5,28 +5,28 @@ import ( "log" "net/http" "strconv" - "math/rand" + // "math/rand" ) -func consumeCPUMemory(n int) { - result := make([][]float64, 0) +// func consumeCPUMemory(n int) { +// result := make([][]float64, 0) - for i := 0; i < n; i++ { - // Consume CPU by computing the sum of a large random array - arr := make([]float64, 10000) - for j := 0; j < len(arr); j++ { - arr[j] = rand.Float64() - } - sum := 0.0 - for _, num := range arr { - sum += num - } +// for i := 0; i < n; i++ { +// // Consume CPU by computing the sum of a large random array +// arr := make([]float64, 10000) +// for j := 0; j < len(arr); j++ { +// arr[j] = rand.Float64() +// } +// sum := 0.0 +// for _, num := range arr { +// sum += num +// } - // Consume memory by appending the array to the result list - result = append(result, arr) - } -} +// // Consume memory by appending the array to the result list +// result = append(result, arr) +// } +// } func byteHandler(w http.ResponseWriter, r *http.Request){ @@ -47,7 +47,7 @@ func byteHandler(w http.ResponseWriter, r *http.Request){ http.Error(w, "Invalid 'bytes' parameter", http.StatusBadRequest) return } - consumeCPUMemory(10) + // consumeCPUMemory(10) // Create a byte slice of the specified length data := make([]byte, numBytes) // Write the byte slice as the response diff --git a/app-simulate/deploy/02-deployment.yaml b/app-simulate/deploy/02-deployment.yaml index 29ae550..355dc13 100644 --- a/app-simulate/deploy/02-deployment.yaml +++ b/app-simulate/deploy/02-deployment.yaml @@ -25,7 +25,7 @@ spec: spec: containers: - name: app-simulate - image: 832438989008.dkr.ecr.ap-southeast-1.amazonaws.com/app-simulate@sha256:041a54be3aa484c4ecfa965f62e760ea03e3004bc55997ed23e8e88daff37cbb + image: 832438989008.dkr.ecr.ap-southeast-1.amazonaws.com/app-simulate@sha256:9d1390eb046ad3d93361593541f9c0573454e5f30ff8a08e17d02d7b96bad7f0 ports: - containerPort: 5000 livenessProbe: diff --git a/system/ops/istio-monitor/prometheus.yaml b/system/ops/istio-monitor/prometheus.yaml index 517a5f4..751423f 100644 --- a/system/ops/istio-monitor/prometheus.yaml +++ b/system/ops/istio-monitor/prometheus.yaml @@ -59,7 +59,7 @@ data: action: keep regex: request-simulate - job_name: app-loadtest - metrics_path: /stats/prometheus + metrics_path: /metrics kubernetes_sd_configs: - role: endpoints relabel_configs: