Skip to content

Commit

Permalink
updated locust version
Browse files Browse the repository at this point in the history
  • Loading branch information
igalonso committed Jun 13, 2023
1 parent 5839f5d commit f994277
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 67 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/v2/load-generator/stop.sh
/v2/load-generator/test.sh
/v2/load-generator/backend/_pycache_/*
/v2/load-generator/backend/services/_pycache_/*
/v2/load-generator/backend/services/*/_pycache_/*
/v2/load-generator/config/targetservers/edge.json
/v2/load-generator/config/targetservers/edge.json.backup
/v2/load-generator/config/edge.json
Expand Down Expand Up @@ -49,4 +49,5 @@
/v1/load-generator/proxies/Load-Generator-User/config.json
/v1/load-generator-key*
/v1/start*
/v1/stop*
/v1/stop*
.buildt
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
markupsafe==2.0.1
Flask==1.1.4
# opencensus-ext-stackdriver 0.7.4 depends on google-cloud-monitoring<1.0.0 and >=0.30.0
google-cloud-monitoring==0.36.0
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
markupsafe==2.0.1
Flask==1.1.4
# opencensus-ext-stackdriver 0.7.4 depends on google-cloud-monitoring<1.0.0 and >=0.30.0
google-cloud-monitoring==0.36.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
markupsafe==2.0.1
Flask==1.1.4
# opencensus-ext-stackdriver 0.7.4 depends on google-cloud-monitoring<1.0.0 and >=0.30.0
google-cloud-monitoring==0.36.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
markupsafe==2.0.1
Flask==1.1.4
# opencensus-ext-stackdriver 0.7.4 depends on google-cloud-monitoring<1.0.0 and >=0.30.0
google-cloud-monitoring==0.36.0
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions v2/load-generator/backend/services/users/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
markupsafe==2.0.1
Flask==1.1.4
# opencensus-ext-stackdriver 0.7.4 depends on google-cloud-monitoring<1.0.0 and >=0.30.0
google-cloud-monitoring==0.36.0
Expand Down
6 changes: 3 additions & 3 deletions v2/load-generator/config/edge.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"Load-Generator-Recommendation",
"Load-Generator-Users"
],
"quota": "300",
"quota": "3000",
"quotaInterval": "1",
"quotaTimeUnit": "hour",
"scopes": []
Expand All @@ -71,7 +71,7 @@
"proxies": [
"Load-Generator-Catalog"
],
"quota": "1000",
"quota": "10000",
"quotaInterval": "1",
"quotaTimeUnit": "hour",
"scopes": []
Expand All @@ -94,7 +94,7 @@
"Load-Generator-Checkout",
"Load-Generator-Catalog"
],
"quota": "50",
"quota": "100",
"quotaInterval": "1",
"quotaTimeUnit": "hour",
"scopes": []
Expand Down
8 changes: 7 additions & 1 deletion v2/load-generator/consumers/load-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ if [ $WORKLOAD_LEVEL = "low" ]; then
concurrent=1
requests=5
fi
if [ $WORKLOAD_LEVEL = "test" ]; then
concurrent=1
requests=1
fi

env TOKEN=$GCP_TOKEN APIGEE_ORG=$APIGEE_ORG APIGEE_ENV=$APIGEE_ENV locust --host=https://$HOST/v1 --no-web -c $concurrent -r $requests -f locust-load.py
echo "Requests: "+ $requests
echo $concurrent
env TOKEN=$GCP_TOKEN APIGEE_ORG=$APIGEE_ORG APIGEE_ENV=$APIGEE_ENV locust --host=https://$HOST/v1 --headless -u $concurrent -r $requests -f locust-load.py
119 changes: 62 additions & 57 deletions v2/load-generator/consumers/locust-load.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import requests
import os
import json
from locust import HttpLocust, TaskSet
import time
from locust import HttpUser, task, between



Expand Down Expand Up @@ -143,60 +144,64 @@ def returnPayload():
else:
return {"content":"something"}

def starting(l):
print("Starting load")

#Catalog functions
def catalogGetList(l):
l.client.get("/catalog?apikey="+selectRandomApp("catalog") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def catalogGet(l):
l.client.get("/catalog/"+randomNum()+"?apikey="+selectRandomApp("catalog") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def catalogPost(l):
l.client.post("/catalog?apikey="+selectRandomApp("catalog"),{"product":"this is a new product"} ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})

#Checkout functions

def checkoutGetList(l):
l.client.get("/checkout?apikey="+selectRandomApp("checkout") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def checkoutGet(l):
l.client.get("/checkout/"+randomNum()+"?apikey="+selectRandomApp("checkout") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def checkoutPost(l):
l.client.post("/checkout?apikey="+selectRandomApp("checkout"),{"cart":"this is a new cart"} ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})

#Loyalty functions

def loyaltyGetList(l):
l.client.get("/loyalty?apikey="+selectRandomApp("loyalty") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def loyaltyGet(l):
l.client.get("/loyalty/"+randomNum()+"?apikey="+selectRandomApp("loyalty") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def loyaltyPost(l):
l.client.post("/loyalty?apikey="+selectRandomApp("loyalty"),{"loyalty":"this is a new loyalty"} ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})

#Loyalty functions

def recommendationGetList(l):
l.client.get("/recommendation?apikey="+selectRandomApp("recommendation") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def recommendationGet(l):
l.client.get("/recommendation/"+randomNum()+"?apikey="+selectRandomApp("recommendation") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def recommendationPost(l):
l.client.post("/recommendation?apikey="+selectRandomApp("recommendation"),returnPayload() ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})

#Loyalty functions

def userGetList(l):
l.client.get("/user?apikey="+selectRandomApp("user") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def userGet(l):
l.client.get("/user/"+randomNum()+"?apikey="+selectRandomApp("user") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})
def userPost(l):
l.client.post("/user?apikey="+selectRandomApp("user"),returnPayload() ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)})


class UserBehavior(TaskSet):

def on_start(self):
self.client.verify = False
starting(self)

class MyUser(HttpUser):


def catalogGetList(self):
url = "/catalog/"+randomNum()+"?apikey="+selectRandomApp("catalog")
response = self.client.get(url,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
time.sleep(1)

def catalogGet(self):
self.client.get("/catalog/"+randomNum()+"?apikey="+selectRandomApp("catalog") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)

def catalogPost(self):
self.client.post("/catalog?apikey="+selectRandomApp("catalog"),{"product":"this is a new product"} ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)

#Checkout functions

def checkoutGetList(l):
l.client.get("/checkout?apikey="+selectRandomApp("checkout") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
time.sleep(1)

def checkoutGet(l):
l.client.get("/checkout/"+randomNum()+"?apikey="+selectRandomApp("checkout") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)

def checkoutPost(l):
l.client.post("/checkout?apikey="+selectRandomApp("checkout"),{"cart":"this is a new cart"} ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)

#Loyalty functions

def loyaltyGetList(l):
l.client.get("/loyalty?apikey="+selectRandomApp("loyalty") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
time.sleep(1)

def loyaltyGet(l):
l.client.get("/loyalty/"+randomNum()+"?apikey="+selectRandomApp("loyalty") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
def loyaltyPost(l):
l.client.post("/loyalty?apikey="+selectRandomApp("loyalty"),{"loyalty":"this is a new loyalty"} ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)

#Loyalty functions

def recommendationGetList(l):
l.client.get("/recommendation?apikey="+selectRandomApp("recommendation") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
time.sleep(1)
def recommendationGet(l):
l.client.get("/recommendation/"+randomNum()+"?apikey="+selectRandomApp("recommendation") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
def recommendationPost(l):
l.client.post("/recommendation?apikey="+selectRandomApp("recommendation"),returnPayload() ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)

#Loyalty functions

def userGetList(l):
l.client.get("/user?apikey="+selectRandomApp("user") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
time.sleep(1)
def userGet(l):
l.client.get("/user/"+randomNum()+"?apikey="+selectRandomApp("user") ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
def userPost(l):
l.client.post("/user?apikey="+selectRandomApp("user"),returnPayload() ,headers={"Load-Generator-Version": "2.1","User-Agent": random.choice(agents),"X-Forwarded-For": random.choice(ips)}, verify=False)
tasks = {
loyaltyGetList: 1,
loyaltyGet: 5,
Expand All @@ -213,7 +218,7 @@ def on_start(self):
catalogGet: 8,
catalogGetList: 3,
catalogPost: 1}
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait=5000
max_wait=9000
wait_time = between(0.5, 10)

if __name__ == "__main__":
locust.main()
5 changes: 2 additions & 3 deletions v2/load-generator/consumers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
locustio==0.9.0
Flask==1.1.1
gevent==1.4.0
locust
Flask==2.2.2
2 changes: 1 addition & 1 deletion v2/load-generator/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ if [ $DEPLOYMENT == "all" ] || [ $DEPLOYMENT == "gcp" ]; then
gcloud builds submit --tag gcr.io/$GPROJECT_GCP/load-test
gcloud compute addresses create $(echo "v2-1-load-locust-ip-"$RAND) --region europe-west2
ADDR=$(gcloud compute addresses describe v2-1-load-locust-ip-$(echo $RAND) --region europe-west2 --format json | jq -r '.address')
gcloud compute instances create-with-container $(echo "v2-1-load-locust-"$RAND) --machine-type=e2-standard-2 --container-image gcr.io/$GPROJECT_GCP/load-test --address $ADDR --zone europe-west2-b
gcloud compute instances create-with-container $(echo "v2-1-load-locust-"$RAND) --machine-type=e2-standard-2 --container-image gcr.io/$GPROJECT_GCP/load-test --address $ADDR --zone europe-west2-b --subnet=default
fi


Expand Down

0 comments on commit f994277

Please sign in to comment.