DEV Community

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

Posted on • Edited on

3

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!

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay