loadgenerator prototype
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
dbe99160bc
commit
8c3d36d81e
5 changed files with 104 additions and 0 deletions
27
kubernetes-manifests/loadgenerator.yaml
Normal file
27
kubernetes-manifests/loadgenerator.yaml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: loadgenerator
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: loadgenerator
|
||||||
|
spec:
|
||||||
|
initContainers:
|
||||||
|
- name: wait-frontend
|
||||||
|
image: alpine:3.6
|
||||||
|
command: ['sh', '-c', 'until wget -qO- "http://${FRONTEND_ADDR}"; do echo "waiting for ${FRONTEND_ADDR}"; sleep 2; done;']
|
||||||
|
containers:
|
||||||
|
- name: server
|
||||||
|
image: loadgenerator
|
||||||
|
env:
|
||||||
|
- name: FRONTEND_ADDR
|
||||||
|
value: "frontend:8080"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 64Mi
|
||||||
|
limits:
|
||||||
|
cpu: 200m
|
||||||
|
memory: 128Mi
|
|
@ -22,6 +22,8 @@ build:
|
||||||
workspace: src/cartservice
|
workspace: src/cartservice
|
||||||
- imageName: frontend
|
- imageName: frontend
|
||||||
workspace: src/frontend
|
workspace: src/frontend
|
||||||
|
- imageName: loadgenerator
|
||||||
|
workspace: src/loadgenerator
|
||||||
deploy:
|
deploy:
|
||||||
kubectl:
|
kubectl:
|
||||||
manifests:
|
manifests:
|
||||||
|
|
7
src/loadgenerator/Dockerfile
Normal file
7
src/loadgenerator/Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FROM python:3
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
ENTRYPOINT locust --host="http://${FRONTEND_ADDR}" --no-web -c=10
|
66
src/loadgenerator/locustfile.py
Normal file
66
src/loadgenerator/locustfile.py
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import random
|
||||||
|
from locust import HttpLocust, TaskSet
|
||||||
|
|
||||||
|
products = [
|
||||||
|
'0PUK6V6EV0',
|
||||||
|
'1YMWWN1N4O',
|
||||||
|
'2ZYFJ3GM2N',
|
||||||
|
'66VCHSJNUP',
|
||||||
|
'6E92ZMYYFZ',
|
||||||
|
'9SIQT8TOJO',
|
||||||
|
'L9ECAV7KIM',
|
||||||
|
'LS4PSXUNUM',
|
||||||
|
'OLJCESPC7Z']
|
||||||
|
|
||||||
|
def index(l):
|
||||||
|
l.client.get("/")
|
||||||
|
|
||||||
|
def setCurrency(l):
|
||||||
|
currencies = ['EUR', 'USD', 'JPY', 'CAD']
|
||||||
|
l.client.post("/setCurrency",
|
||||||
|
{'currency_code': random.choice(currencies)})
|
||||||
|
|
||||||
|
def browseProduct(l):
|
||||||
|
l.client.get("/product/" + random.choice(products))
|
||||||
|
|
||||||
|
def viewCart(l):
|
||||||
|
l.client.get("/cart")
|
||||||
|
|
||||||
|
def addToCart(l):
|
||||||
|
product = random.choice(products)
|
||||||
|
l.client.get("/product/" + product)
|
||||||
|
l.client.post("/cart", {
|
||||||
|
'product_id': product,
|
||||||
|
'quantity': random.choice([1,2,3,4,5,10])})
|
||||||
|
|
||||||
|
def checkout(l):
|
||||||
|
addToCart(l)
|
||||||
|
l.client.post("/cart/checkout", {
|
||||||
|
'email': 'someone@example.com',
|
||||||
|
'street_address': '1600 Amphitheatre Parkway',
|
||||||
|
'zip_code': '94043',
|
||||||
|
'city': 'Mountain View',
|
||||||
|
'state': 'CA',
|
||||||
|
'country': 'United States',
|
||||||
|
'credit_card_number': '4432-8015-6152-0454',
|
||||||
|
'credit_card_expiration_month': '1',
|
||||||
|
'credit_card_expiration_year': '2019',
|
||||||
|
'credit_card_cvv': '672',
|
||||||
|
})
|
||||||
|
|
||||||
|
class UserBehavior(TaskSet):
|
||||||
|
|
||||||
|
def on_start(self):
|
||||||
|
index(self)
|
||||||
|
|
||||||
|
tasks = {index: 1,
|
||||||
|
setCurrency: 2,
|
||||||
|
browseProduct: 10,
|
||||||
|
addToCart: 2,
|
||||||
|
viewCart: 3,
|
||||||
|
checkout: 1}
|
||||||
|
|
||||||
|
class WebsiteUser(HttpLocust):
|
||||||
|
task_set = UserBehavior
|
||||||
|
min_wait = 1000
|
||||||
|
max_wait = 2000
|
2
src/loadgenerator/requirements.txt
Normal file
2
src/loadgenerator/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
locustio==0.8.1
|
||||||
|
pyzmq==17.0.0
|
Loading…
Reference in a new issue