DevOps

How to Perform Load Testing on a Dockerized Web App Using Apache JMeter


Introduction

Apache JMeter is a powerful open-source tool for performance testing. Here’s a detailed step by step guide to load test your web application running in Docker.

Step 1: Install Apache JMeter

Before starting, ensure you have JMeter installed.

1.1 Install JMeter on Your Machine

  • Windows & Mac:

    • Download JMeter from the official site.

    • Extract the downloaded .zip file.

    • Navigate to the bin folder and run jmeter.bat (Windows) or jmeter (Mac/Linux).

  • Linux (via Terminal):

sudo apt updatesudo apt install jmeter -y
  • Docker Alternative (If you want to run JMeter inside a Docker container)

docker run -it --rm -v $(pwd):/tests -w /tests justb4/jmeter -n -t test_plan.jmx 

Step 2: Start Your Web App in Docker

  • Before running JMeter, ensure your application is up and running in Docker.
  • Navigate to your project directory where your docker-compose.yml is located.
  • Start the web app: docker-compose up -d
  • Verify that your application is running by visiting the app URL in your browser (http://localhost:8000 or your assigned port).

 

Step 3: Create a JMeter Test Plan

A test plan defines the load test scenario. Follow these steps:

3.1 Open JMeter

  • Run JMeter by executing:

jmeter

A GUI will open.

3.2 Add a Thread Group (Defines Users and Load)

  • Right click Test Plan → Add → Threads (Users) → Thread Group.

Configure:

  • Number of Threads (Users): e.g., 100 (simulates 100 users).

  • Ramp-up Period (seconds): e.g., 10 (users added over 10 sec).

  • Loop Count: Forever or 5 (how many times to repeat requests).

3.3 Add an HTTP Request Sampler

  • Right-click Thread Group → Add → Sampler → HTTP Request.

Configure:

  • Server Name or IP: localhost (or your Docker container’s IP).

  • Port: 8000 (or the port your app runs on).

  • HTTP Method: GET or POST (depending on API).

  • Path: /login or /api/data (endpoint you want to test).

  • If it's a POST request, add Body Data or Parameters.

3.4 Add Listeners (To View Test Results)

  • Right-click Thread Group → Add → Listener.

  • Select View Results Tree, Summary Report or Graph Results.

     

Step 4: Run the Load Test Locally

Once the test plan is ready, execute it.

  • Click the Run button in JMeter.

  • Monitor the results in the View Results Tree panel.

  • Analyze response times, error rates and throughput.

     

Step 5: Running JMeter in CLI Mode (Headless Execution)

For better performance, run JMeter in command line mode:

  • Save the test plan as - test_plan.jmx.

  • Run JMeter using:

jmeter -n -t test_plan.jmx -l results.jtl
  • -n → Non-GUI mode.  
  • -t test_plan.jmx → Test plan file.
  • -l results.jtl → Log file for results.

Ready to transform your business with our technology solutions? Contact Us  today to Leverage Our DevOps Expertise. 

0

Devops

Related Center Of Excellence