DEV Community

Cover image for Load Testing MongoDB with Locust
Hejun Wong
Hejun Wong

Posted on • Edited on

Load Testing MongoDB with Locust

What is Locust.io?

Locust is an open source load testing tool written in Python. Since it is written in Python, it is possible to containerise it and deploy it on Kubernetes.

Mongolocust allows you to code up MongoDB CRUD operations in Python and visualise their executions in a browser.

Why Load Test?

Load test helps us to understand how well our database performs under various levels of stress, identify performance bottlenecks and presents an opportunity to test our database's auto scaling capabilities.

Goals

In this article, you will learn how to deploy locust on AWS EKS and load test your MongoDB cluster.

Pre-requisites

Steps

Install kubectl, the Kubernetes CLI version of a swiss army knife

brew install kubectl
Enter fullscreen mode Exit fullscreen mode

Install eksctl, a simple CLI tool for creating and managing clusters on AWS EKS

brew tap weaveworks/tap
brew install weaveworks/tap/eksctl
Enter fullscreen mode Exit fullscreen mode

Create AWS EKS Cluster

eksctl --profile aws-tester create cluster \
--name mongo-locust-cluster \
--version 1.30 \
--region ap-southeast-1 \
--nodegroup-name locust-nodes \
--node-type t3.medium \
--nodes 2
Enter fullscreen mode Exit fullscreen mode

Pull a copy of Mongolocust codes

git clone https://github.com/sabyadi/mongolocust.git
Enter fullscreen mode Exit fullscreen mode

Set CLUSTER_URL within k8s/secret.yaml to your MongoDB Cluster's URL

cd mongolocust/k8s
vi secret.yaml
Enter fullscreen mode Exit fullscreen mode

Deploy Mongolocust on AWS EKS

cd ..
./redeploy.sh
Enter fullscreen mode Exit fullscreen mode

Forward 8089 port from master service to localhost

kubectl port-forward service/master 8089:8089
Enter fullscreen mode Exit fullscreen mode

Access Locust Web Interface at (http://localhost:8089)

Scale Locust Workers

kubectl scale deployment locust-worker-deployment --replicas 10
Enter fullscreen mode Exit fullscreen mode

Obtain Kubernetes nodes' IP addresses and whitelist on MongoDB Atlas

kubectl get nodes -o wide 
Enter fullscreen mode Exit fullscreen mode

Have fun load testing your MongoDB Cluster!

Top comments (0)