Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter and Docker

Tags:

docker

jmeter

I saw some blog posts where people talk about JMeter and Docker. I understand that Docker will be helpful for setting up a container with all the dependencies. But they all run/create the containers in the same host. So ideally all the containers will share the host resources. It is like you run multiple instances of jmeter in the same host. It will not be helpful to generate more load.

When a host has 12GB RAM, I think 1 instance of JMeter with 10GB heap can generate more load than running 10 containers with 1 jmeter instance in each container.

What is the point of running docker here?

like image 802
KitKarson Avatar asked Mar 12 '16 16:03

KitKarson


2 Answers

I made an automatic solution that can be easily integrated with Jenkins.

The dockerfile should be extended from java8 and add the JMeter build. This Docker image I will call jmeter-base:

FROM java:8

RUN mkdir /jmeter \
    && cd /jmeter/ \
    && wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-3.3.tgz \
    && tar -xvzf apache-jmeter-3.3.tgz \
    && rm apache-jmeter-3.3.tgz

ENV JMETER_HOME /jmeter/apache-jmeter-3.3/

# Add Jmeter to the Path
ENV PATH $JMETER_HOME/bin:$PATH

If you want to use a master-slave solution, this is the jmeter master Dockerfile:

FROM jmeter-base

WORKDIR $JMETER_HOME
# Ports to be exposed from the container for JMeter Master
RUN mkdir scripts

EXPOSE 60000

And this is the jmeter slave Dockerfile:

FROM jmeter-base

# Ports to be exposed from the container for JMeter Slaves/Server
EXPOSE 1099 50000

# Application to run on starting the container
ENTRYPOINT $JMETER_HOME/bin/jmeter-server \
                        -Dserver.rmi.localport=50000 \
-Dserver_port=1099

Now, with the both images, you should execute a script to execute you should know all slave IPs. This script make all the job:

#!/bin/bash

COUNT=${1-1}

docker build -t jmeter-base jmeter-base
docker-compose build && docker-compose up -d && docker-compose scale master=1 slave=$COUNT

SLAVE_IP=$(docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq) | grep slave | awk -F' ' '{print $2}' | tr '\n' ',' | sed 's/.$//')
WDIR=`docker exec -it master /bin/pwd | tr -d '\r'`
mkdir -p results
for filename in scripts/*.jmx; do
    NAME=$(basename $filename)
    NAME="${NAME%.*}"
    eval "docker cp $filename master:$WDIR/scripts/"
    eval "docker exec -it master /bin/bash -c 'mkdir $NAME && cd $NAME && ../bin/jmeter -n -t ../$filename -R$SLAVE_IP'"
    eval "docker cp master:$WDIR/$NAME results/"
done

docker-compose stop && docker-compose rm -f
like image 93
Victor Avatar answered Oct 09 '22 23:10

Victor


I came to understand from this post from a friend of mine that we should not be running multiple docker containers in the same host to generate more load.

http://www.testautomationguru.com/jmeter-distributed-load-testing-using-docker/

Instead the usage of docker here is to quickly setup the jmeter environment.

like image 20
KitKarson Avatar answered Oct 10 '22 00:10

KitKarson