load generation

This commit is contained in:
Steve Waterworth
2018-02-13 12:35:08 +00:00
parent 94edb20bf9
commit 449e43d074
3 changed files with 62 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ The application is built using these technologies:
- Golang
- MongoDB
- Redis
- MySQL
- MySQL ([Maxmind](http://www.maxmind.com) data)
- RabbitMQ
- AngularJS (1.x)
@@ -32,9 +32,9 @@ You can run it locally for testing
If you are running it locally on a Linux host you can also run the Instana [agent](https://docs.instana.io/quick_start/agent_setup/container/docker/) locally, unfortunately the agent is currently not supported on Mac.
## Kubernetes
The Docker container images are all available on [Docker Hub](https://hub.docker.com/u/steveww/). The deployment and service definition files using these images are in the K8s directory, use these to deploy to a Kubernetes cluster. If you pushed your own images to your own registry the deployment files will need to be updated to pull from your registry; using [kompose](https://github.com/kubernetes/kompose) may be of assistance here.
The Docker container images are all available on [Docker Hub](https://hub.docker.com/u/steveww/). The deployment and service definition files using these images are in the *K8s* directory, use these to deploy to a Kubernetes cluster. If you pushed your own images to your registry the deployment files will need to be updated to pull from your registry; using [kompose](https://github.com/kubernetes/kompose) may be of assistance here.
If you want to deploy Stan's Robot Shop to Google Compute you will need to edit the K8s/web-service.yaml file and change the type from NodePort to LoadBalancer.
If you want to deploy Stan's Robot Shop to Google Compute you will need to edit the *K8s/web-service.yaml* file and change the type from NodePort to LoadBalancer. This can also be done in the Google Compute console.
*NOTE* I have found some issues with kompose reading the *.env* correctly, just export the variables in the shell environment to work around this.
@@ -51,10 +51,12 @@ Deploy the agent
$ kubectl create -f instana/instana-agent.yaml
The agent configuration only runs the agent on nodes with the appropriate label.
The agent configuration only runs the agent on nodes with the appropriate label. For minikube.
$ kubectl label node minikube agent=instana
There is also a handy script *instana/label.sh* which labels all the nodes.
## Acessing the Store
If you are running the store locally via *docker-compose up* then, the store front is available on localhost port 8080 [http://localhost:8080](http://localhost:8080/)
@@ -62,7 +64,11 @@ If you are running the store on Kubernetes via minikube then, the store front is
$ minikube ip
If you are using a cloud Kubernetes / Openshift / Mesosphere then it will be available on the load balancer of that system. There will be specific blog posts on the Instana site covering these scenarios.
## Load Generation
A separate load generation utility is provided in the *load-gen* directory. This is not automatically run when the application is started. The load generator is built with Python and [Locust](https://locust.io). The *build.sh* script builds the Docker image, optionally taking *push* as the first argument to also push the image to the registry. The registry and tag settings are loaded from the *.env* file in the parent directory. The script *load-gen.sh* runs the image, edit this and set the HOST environment variable to point the load at where you are running the application. You could run this inside an orchestration system (K8s) as well if you want to, how to do this is left as an exercise for the reader.
## TO DO
- End User Monitoring
- Load generation script

View File

@@ -4,7 +4,7 @@
docker run \
-it \
--rm \
--network robotshop_robot-shop \
-e 'HOST=http://web:8080' \
--network=host \
-e 'HOST=http://localhost:8080' \
steveww/rs-load

View File

@@ -1,4 +1,5 @@
from locust import HttpLocust, TaskSet, task
from random import choice
class UserBehavior(TaskSet):
def on_start(self):
@@ -6,13 +7,56 @@ class UserBehavior(TaskSet):
print('Starting')
@task
def index(self):
self.client.get("/")
def login(self):
credentials = {
'name': 'user',
'password': 'password'
}
res = self.client.post('/api/user/login', json=credentials)
print('login {}'.format(res.status_code))
@task
def user(self):
res = self.client.get("/api/user/uniqueid")
print('User {}'.format(res.content))
def load(self):
self.client.get('/')
user = self.client.get('/api/user/uniqueid').json()
uniqueid = user['uuid']
print('User {}'.format(uniqueid))
self.client.get('/api/catalogue/categories')
# all products in catalogue
products = self.client.get('/api/catalogue/products').json()
for i in range(2):
item = None
while True:
item = choice(products)
if item['instock'] != 0:
break
self.client.get('/api/catalogue/product/{}'.format(item['sku']))
self.client.get('/api/cart/add/{}/{}/1'.format(uniqueid, item['sku']))
cart = self.client.get('/api/cart/cart/{}'.format(uniqueid)).json()
item = choice(cart['items'])
self.client.get('/api/cart/update/{}/{}/2'.format(uniqueid, item['sku']))
# country codes
code = choice(self.client.get('/api/shipping/codes').json())
city = choice(self.client.get('/api/shipping/cities/{}'.format(code['code'])).json())
print('code {} city {}'.format(code, city))
shipping = self.client.get('/api/shipping/calc/{}'.format(city['uuid'])).json()
shipping['location'] = '{} {}'.format(code['name'], city['name'])
print('Shipping {}'.format(shipping))
# POST
cart = self.client.post('/api/shipping/confirm/{}'.format(uniqueid), json=shipping).json()
print('Final cart {}'.format(cart))
order = self.client.post('/api/payment/pay/{}'.format(uniqueid), json=cart).json()
print('Order {}'.format(order))
# delete cart
self.client.delete('/api/cart/cart/{}'.format(uniqueid))
class WebsiteUser(HttpLocust):
task_set = UserBehavior