loadgenerator prototype

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-06-29 16:35:57 -07:00
parent dbe99160bc
commit 8c3d36d81e
5 changed files with 104 additions and 0 deletions

View 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

View file

@ -22,6 +22,8 @@ build:
workspace: src/cartservice
- imageName: frontend
workspace: src/frontend
- imageName: loadgenerator
workspace: src/loadgenerator
deploy:
kubectl:
manifests:

View 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

View 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

View file

@ -0,0 +1,2 @@
locustio==0.8.1
pyzmq==17.0.0