Skip to content

Commit

Permalink
chore: replace AUTOPUSH_ENDPOINT_URL and AUTOPUSH_SERVER_URL with LOC…
Browse files Browse the repository at this point in the history
…UST_HOST in load tests (#523)

- Update Python dependencies
- Update stage server URL in load tests
- Update Kubernetes definitions to mitigate cluster creation errors
- Re-calibrate load tests after GCP migration

Closes SYNC-3974 & Closes SYNC-4034
  • Loading branch information
Trinaa authored Dec 13, 2023
1 parent c7fa922 commit b72dee1
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 253 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ POETRY := poetry --directory $(TESTS_DIR)
DOCKER_COMPOSE := docker compose
PYPROJECT_TOML := $(TESTS_DIR)/pyproject.toml
FLAKE8_CONFIG := $(TESTS_DIR)/.flake8
STAGE_SERVER_URL := "wss://autopush.stage.mozaws.net"
STAGE_ENDPOINT_URL := "https://updates-autopush.stage.mozaws.net"
LOCUST_HOST := "wss://autoconnect.stage.mozaws.net"

.PHONY: ddb

Expand Down Expand Up @@ -48,7 +47,7 @@ lint:
$(POETRY) run mypy $(TESTS_DIR) --config-file=$(PYPROJECT_TOML)

load:
SERVER_URL=$(STAGE_SERVER_URL) ENDPOINT_URL=$(STAGE_ENDPOINT_URL) \
LOCUST_HOST=$(LOCUST_HOST) \
$(DOCKER_COMPOSE) \
-f $(LOAD_TEST_DIR)/docker-compose.yml \
-p autopush-rs-load-tests \
Expand Down
2 changes: 1 addition & 1 deletion tests/load/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ COPY ./tests/load/locustfiles ./tests/load/locustfiles
EXPOSE 8089 5557

USER locust
ENTRYPOINT locust -f "tests/load/locustfiles/locustfile.py,tests/load/locustfiles/load.py" --websocket_url ${SERVER_URL} --endpoint_url ${ENDPOINT_URL}
ENTRYPOINT locust -f "tests/load/locustfiles/locustfile.py,tests/load/locustfiles/load.py"
12 changes: 4 additions & 8 deletions tests/load/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ Environment variables, listed bellow or specified by [Locust][12], can be set in

| Environment Variable | Node(s) | Description |
|----------------------|-----------------|--------------------------------------|
| SERVER_URL | master & worker | The autopush web socket address |
| ENDPOINT_URL | master & worker | The autopush HTTP address |
| AUTOPUSH_WAIT_TIME | master & worker | The wait time between task execution |

#### 2. Host Locust via Docker
Expand All @@ -67,10 +65,8 @@ make load
* ShapeClass: Default
* Number of users: 1
* Spawn rate: 1
* Host: 'https://updates-autopush.stage.mozaws.net'
* Host: 'wss://autoconnect.stage.mozaws.net'
* Duration (Optional): 10m
* Websocket URL: 'wss://autopush.stage.mozaws.net'
* Endpoint URL: 'https://updates-autopush.stage.mozaws.net'
* Select "Start Swarming"

#### 2. Stop Load Test
Expand Down Expand Up @@ -134,6 +130,8 @@ The load tests can be executed from the [contextual-services-test-eng cloud shel
```shell
./tests/load/setup_k8s.sh
```
**Note:** Locust requires CPU affinity to execute most efficiently and can only make
use of a single core at a time. Warnings will be logged if CPU usage exceeds 90%.
* The cluster creation process will take some time. It is considered complete, once
an external IP is assigned to the `locust_master` node. Monitor the assignment via
a watch loop:
Expand Down Expand Up @@ -164,9 +162,7 @@ The load tests can be executed from the [contextual-services-test-eng cloud shel

* Set up the load test parameters:
* ShapeClass: 'AutopushLoadTestShape'
* Host: 'https://updates-autopush.stage.mozaws.net'
* Websocket URL: 'wss://autopush.stage.mozaws.net'
* Endpoint URL: 'https://updates-autopush.stage.mozaws.net'
* Host: 'wss://autoconnect.stage.mozaws.net'
* Select "Start Swarming"

#### 2. Stop Load Test
Expand Down
6 changes: 1 addition & 5 deletions tests/load/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ services:
- "8089:8089"
environment:
LOCUST_USERCLASS_PICKER: true
LOCUST_HOST: ${AUTOPUSH_HOST}
LOCUST_HOST: ${LOCUST_HOST}
LOCUST_LOGLEVEL: "INFO"
SERVER_URL: ${SERVER_URL}
ENDPOINT_URL: ${ENDPOINT_URL}
command: >
--master
Expand All @@ -25,7 +23,5 @@ services:
environment:
LOCUST_MASTER_NODE_HOST: locust_master
LOCUST_LOGLEVEL: "INFO"
SERVER_URL: ${SERVER_URL}
ENDPOINT_URL: ${ENDPOINT_URL}
command: >
--worker
10 changes: 4 additions & 6 deletions tests/load/kubernetes-config/locust-master-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ spec:
value:
- name: LOCUST_CSV
value:
- name: LOCUST_HOST
value:
- name: LOCUST_LOGLEVEL
value:
- name: LOCUST_LOGFILE
value:
- name: SERVER_URL
value:
- name: ENDPOINT_URL
value:
ports:
- name: loc-master-web
containerPort: 8089
Expand All @@ -46,8 +44,8 @@ spec:
protocol: TCP
resources:
limits:
cpu: 1
cpu: 2
memory: 3Gi
requests:
cpu: 0.9
cpu: 1
memory: 2Gi
8 changes: 2 additions & 6 deletions tests/load/kubernetes-config/locust-worker-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ spec:
value:
- name: LOCUST_LOGFILE
value:
- name: SERVER_URL
value:
- name: ENDPOINT_URL
value:
resources:
limits:
cpu: 1
cpu: 2
memory: 3Gi
requests:
cpu: 0.9
cpu: 1
memory: 2Gi
2 changes: 1 addition & 1 deletion tests/load/locustfiles/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AutopushLoadTestShape(LoadTestShape):
"""

MAX_RUN_TIME: int = 600 # 10 minutes
WORKER_COUNT: int = 150 # Must match value defined in setup_k8s.sh
WORKER_COUNT: int = 300 # Must match value defined in setup_k8s.sh
USERS_PER_WORKER: int = 500 # Number of users supported on a worker running on a n1-standard-2
MAX_USERS: int = WORKER_COUNT * USERS_PER_WORKER
trend: QuadraticTrend
Expand Down
20 changes: 5 additions & 15 deletions tests/load/locustfiles/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from exceptions import ZeroStatusRequestError
from gevent import Greenlet
from locust import FastHttpUser, events, task
from locust.exception import LocustError
from models import (
HelloMessage,
HelloRecord,
Expand All @@ -45,20 +46,6 @@

@events.init_command_line_parser.add_listener
def _(parser: Any):
parser.add_argument(
"--websocket_url",
type=str,
env_var="AUTOPUSH_WEBSOCKET_URL",
required=True,
help="Server URL",
)
parser.add_argument(
"--endpoint_url",
type=str,
env_var="AUTOPUSH_ENDPOINT_URL",
required=True,
help="Endpoint URL",
)
parser.add_argument(
"--wait_time",
type=str,
Expand Down Expand Up @@ -196,8 +183,11 @@ def unsubscribe(self):

def connect(self) -> None:
"""Creates the WebSocketApp that will run indefinitely."""
if not self.host:
raise LocustError("'host' value is unavailable.")

self.ws = websocket.WebSocketApp(
self.environment.parsed_options.websocket_url,
self.host,
header=self.WEBSOCKET_HEADERS,
on_message=self.on_ws_message,
on_error=self.on_ws_error,
Expand Down
7 changes: 3 additions & 4 deletions tests/load/setup_k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CLUSTER='autopush-locust-load-test'
TARGET='https://updates-autopush.stage.mozaws.net'
SCOPE='https://www.googleapis.com/auth/cloud-platform'
REGION='us-central1'
WORKER_COUNT=150
WORKER_COUNT=300
MACHINE_TYPE='n1-standard-2' # 2 CPUs + 7.50GB Memory
BOLD=$(tput bold)
NORM=$(tput sgr0)
Expand All @@ -28,10 +28,9 @@ echo "Image tag for locust is set to: ${LOCUST_IMAGE_TAG}"
ENVIRONMENT_VARIABLES=(
"TARGET_HOST,$TARGET"
'LOCUST_CSV,autopush'
'LOCUST_HOST,wss://autoconnect.stage.mozaws.net'
'LOCUST_LOGLEVEL,INFO'
'LOCUST_LOGFILE,autopush.log'
'SERVER_URL,wss://autopush.stage.mozaws.net'
"ENDPOINT_URL,$TARGET"
)

SetEnvironmentVariables()
Expand Down Expand Up @@ -100,7 +99,7 @@ do
create) #Setup Kubernetes Cluster
echo -e "==================== Creating the GKE cluster "
# The total-max-nodes = WORKER_COUNT + 1 (MASTER)
$GCLOUD container clusters create $CLUSTER --region $REGION --scopes $SCOPE --enable-autoscaling --total-min-nodes "1" --total-max-nodes "151" --scopes=logging-write,storage-ro --addons HorizontalPodAutoscaling,HttpLoadBalancing --machine-type $MACHINE_TYPE
$GCLOUD container clusters create $CLUSTER --region $REGION --scopes $SCOPE --enable-autoscaling --total-min-nodes "1" --total-max-nodes "301" --scopes=logging-write,storage-ro --addons HorizontalPodAutoscaling,HttpLoadBalancing --machine-type $MACHINE_TYPE
SetupGksCluster
break
;;
Expand Down
Loading

0 comments on commit b72dee1

Please sign in to comment.