Skip to content

Commit

Permalink
Update app-loadtest for testing concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisp018 committed May 13, 2023
1 parent 8f4088d commit f70b97c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 42 deletions.
28 changes: 28 additions & 0 deletions app-loadtest/app-loadtest-test.go
Original file line number Diff line number Diff line change
@@ -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)
}
35 changes: 20 additions & 15 deletions app-loadtest/app-loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

}


Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions app-loadtest/deploy/02-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,9 +36,3 @@ spec:
- /app/healthy
initialDelaySeconds: 5
periodSeconds: 5
# readinessProbe:
# httpGet:
# path: /healthz/ready
# port: 5000
# initialDelaySeconds: 5
# periodSeconds: 5
36 changes: 18 additions & 18 deletions app-simulate/app-simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app-simulate/deploy/02-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion system/ops/istio-monitor/prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f70b97c

Please sign in to comment.