|
1 | | -# gcp-golang-performance-test |
| 1 | +# Performance testing on GKE using labstack eacho application |
| 2 | + |
| 3 | +[](https://github.com/DevSecOpsSamples/gcp-golang-performance-test/actions/workflows/build.yml) |
| 4 | +[](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_gcp-golang-performance-test) [](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_gcp-golang-performance-test) |
| 5 | + |
| 6 | +Performance testing on GKE using the https://echo.labstack.com application. |
| 7 | + |
| 8 | + |
| 9 | +## Table of Contents |
| 10 | + |
| 11 | +- [1. Create a GKE cluster](#1-create-a-gke-cluster) |
| 12 | +- [2. Deploy two applications for checking the performance per Pod and scaling](#2-deploy-two-applications-for-checking-the-performance-per-pod-and-scaling) |
| 13 | + - [2.1. Deploy for performance of one Pod](#21-deploy-for-performance-of-one-pod) |
| 14 | + - [2.2. Deploy for Scaling Test](#22-deploy-for-scaling-test) |
| 15 | +- [3. Performance Testing](#3-performance-testing) |
| 16 | + - [3.1. Install the Taurus](#31-install-the-taurus) |
| 17 | + - [3.2. Test for performance of one Pod](#32-test-for-performance-of-one-pod) |
| 18 | + - [3.3. Test with auto scaling](#33-test-with-auto-scaling) |
| 19 | +- [Cleanup](#6-cleanup) |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +### Installation |
| 26 | + |
| 27 | +- [Install the gcloud CLI](https://cloud.google.com/sdk/docs/install) |
| 28 | +- [Install kubectl and configure cluster access](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl) |
| 29 | +- [Installing and Upgrading for the Taurus ](https://gettaurus.org/install/Installation/) |
| 30 | + |
| 31 | +### Set environment variables |
| 32 | + |
| 33 | +```bash |
| 34 | +COMPUTE_ZONE="us-central1" |
| 35 | +# replace with your project |
| 36 | +PROJECT_ID="sample-project" |
| 37 | +``` |
| 38 | + |
| 39 | +### Set GCP project |
| 40 | + |
| 41 | +```bash |
| 42 | +gcloud config set project ${PROJECT_ID} |
| 43 | +gcloud config set compute/zone ${COMPUTE_ZONE} |
| 44 | +``` |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## 1. Create a GKE cluster |
| 49 | + |
| 50 | +Create an Autopilot GKE cluster. It may take around 9 minutes. |
| 51 | + |
| 52 | +```bash |
| 53 | +gcloud container clusters create-auto sample-cluster --region=${COMPUTE_ZONE} |
| 54 | +gcloud container clusters get-credentials sample-cluster |
| 55 | +``` |
| 56 | + |
| 57 | +## 2. Deploy two applications for checking the performance per Pod and scaling |
| 58 | + |
| 59 | +Build and push to GCR: |
| 60 | + |
| 61 | +```bash |
| 62 | +cd app |
| 63 | +docker build -t go-echo-api . --platform linux/amd64 |
| 64 | +docker tag go-echo-api:latest gcr.io/${PROJECT_ID}/go-echo-api:latest |
| 65 | + |
| 66 | +gcloud auth configure-docker |
| 67 | +docker push gcr.io/${PROJECT_ID}/go-echo-api:latest |
| 68 | +``` |
| 69 | + |
| 70 | +```bash |
| 71 | +kubectl get namespaces |
| 72 | + |
| 73 | +kubectl create namespace echo-test |
| 74 | +``` |
| 75 | + |
| 76 | +Two deployments may take around 5 minutes to create a load balancer, including health checking. |
| 77 | + |
| 78 | +## 2.1. Deploy for performance of one Pod |
| 79 | + |
| 80 | +To check request per seconds(RPS) WITHOUT scaling, create and deploy K8s Deployment, Service, HorizontalPodAutoscaler, Ingress, and GKE BackendConfig using the [go-echo-api-onepod-template.yaml](app/go-echo-api-onepod-template.yaml) template file: |
| 81 | + |
| 82 | +```bash |
| 83 | +sed -e "s|<project-id>|${PROJECT_ID}|g" go-echo-api-onepod-template.yaml > go-echo-api-onepod.yaml |
| 84 | +cat go-echo-api-onepod.yaml |
| 85 | + |
| 86 | +kubectl get namespaces |
| 87 | +kubectl apply -f go-echo-api-onepod.yaml -n echo-test --dry-run=client |
| 88 | +``` |
| 89 | + |
| 90 | +Confirm Pod logs and configuration after deployment: |
| 91 | + |
| 92 | +```bash |
| 93 | +kubectl logs -l app=go-echo-api-onepod -n echo-test |
| 94 | + |
| 95 | +kubectl describe pods -n echo-test |
| 96 | + |
| 97 | +kubectl get ingress go-echo-api-onepod-ingress -n echo-test |
| 98 | +``` |
| 99 | + |
| 100 | +## 2.2. Deploy for Scaling Test |
| 101 | + |
| 102 | +To check request per seconds(RPS) with scaling, create and deploy K8s Deployment, Service, HorizontalPodAutoscaler, Ingress, and GKE BackendConfig using the [go-echo-api-template.yaml](app/go-echo-api-template.yaml) template file: |
| 103 | + |
| 104 | +```bash |
| 105 | +sed -e "s|<project-id>|${PROJECT_ID}|g" go-echo-api-template.yaml > go-echo-api.yaml |
| 106 | +cat go-echo-api.yaml |
| 107 | + |
| 108 | +kubectl apply -f go-echo-api.yaml -n echo-test --dry-run=client |
| 109 | +``` |
| 110 | + |
| 111 | +```bash |
| 112 | +kubectl apply -f go-echo-api.yaml -n echo-test |
| 113 | +``` |
| 114 | + |
| 115 | +Confirm Pod logs and configuration after deployment: |
| 116 | + |
| 117 | +```bash |
| 118 | +kubectl logs -l app=go-echo-api -n echo-test |
| 119 | + |
| 120 | +kubectl describe pods -n echo-test |
| 121 | + |
| 122 | +kubectl get ingress go-echo-api-ingress -n echo-test |
| 123 | +``` |
| 124 | + |
| 125 | +Confirm that response of `/` API. |
| 126 | + |
| 127 | +```bash |
| 128 | +LB_IP_ADDRESS=$(gcloud compute forwarding-rules list | grep go-echo-api | awk '{ print $2 }') |
| 129 | +echo ${LB_IP_ADDRESS} |
| 130 | +``` |
| 131 | + |
| 132 | +```bash |
| 133 | +curl http://${LB_IP_ADDRESS}/ |
| 134 | +``` |
| 135 | + |
| 136 | +## 3. Performance Testing |
| 137 | + |
| 138 | +### 3.1. Install the Taurus |
| 139 | + |
| 140 | +https://gettaurus.org/install/Installation/ |
| 141 | + |
| 142 | +```bash |
| 143 | +sudo apt-get update -y |
| 144 | +sudo apt-get install python3 default-jre-headless python3-tk python3-pip python3-dev libxml2-dev libxslt-dev zlib1g-dev net-tools -y |
| 145 | +sudo python3 -m pip install bzt |
| 146 | +sudo apt-get install htop -y |
| 147 | +``` |
| 148 | + |
| 149 | +### 3.2. Test for performance of one Pod |
| 150 | + |
| 151 | +```bash |
| 152 | +cd test |
| 153 | +# test with 300 threads and connection:close option |
| 154 | +bzt echo-bzt-onepod.yaml |
| 155 | +``` |
| 156 | + |
| 157 | +[test/echo-bzt-onepod.yaml](./test/echo-bzt-onepod.yaml) |
| 158 | + |
| 159 | +```bash |
| 160 | +kubectl describe hpa go-echo-api-onepod-hpa -n echo-test |
| 161 | + |
| 162 | +kubectl get hpa go-echo-api-onepod-hpa -n echo-test -w |
| 163 | +``` |
| 164 | + |
| 165 | +### 3.3. Test with auto scaling |
| 166 | + |
| 167 | +```bash |
| 168 | +cd test |
| 169 | +# test with 2000 threads and connection:close option |
| 170 | +bzt echo-bzt.yaml |
| 171 | +``` |
| 172 | + |
| 173 | +[test/echo-bzt.yaml](./test/echo-bzt.yaml) |
| 174 | + |
| 175 | +```bash |
| 176 | +kubectl describe hpa go-echo-api-hpa -n echo-test |
| 177 | + |
| 178 | +kubectl get hpa go-echo-api-hpa -n echo-test -w |
| 179 | +``` |
| 180 | + |
| 181 | +## Cleanup |
| 182 | + |
| 183 | +```bash |
| 184 | +kubectl scale deployment go-echo-api-onepod -n echo-test --replicas=0 |
| 185 | +kubectl scale deployment go-echo-api -n echo-test --replicas=0 |
| 186 | + |
| 187 | +kubectl delete -f app/go-echo-api-onepod.yaml -n echo-test |
| 188 | +kubectl delete -f app/go-echo-api.yaml -n echo-test |
| 189 | +``` |
| 190 | + |
| 191 | +## References |
| 192 | + |
| 193 | +- https://echo.labstack.com |
| 194 | + |
| 195 | +- [Cloud SDK > Documentation > Reference > gcloud container clusters](https://cloud.google.com/sdk/gcloud/reference/container/clusters) |
| 196 | + |
| 197 | +- [Google Kubernetes Engine (GKE) > Documentation > Guides > GKE Ingress for HTTP(S) Load Balancing](https://cloud.google.com/kubernetes-engine/docs/concepts/ingress) |
0 commit comments