From 8f5259b6ce218f8ffeec57fc04cb5c2b782bd959 Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 8 Jun 2016 17:52:59 -0300 Subject: [test] add docker perf tests --- scripts/docker/Dockerfile | 15 +++- scripts/docker/Makefile | 67 ++++++++++++++++-- scripts/docker/TODO | 2 - scripts/docker/files/run-perf-test.sh | 124 ++++++++++++++++++++++++++++++++++ scripts/docker/files/start-server.sh | 57 ++++++++++++++++ scripts/docker/helper/run-test.sh | 67 ++++++++++++++++++ scripts/docker/helper/run-tests.sh | 48 ------------- 7 files changed, 323 insertions(+), 57 deletions(-) create mode 100755 scripts/docker/files/run-perf-test.sh create mode 100755 scripts/docker/helper/run-test.sh delete mode 100755 scripts/docker/helper/run-tests.sh (limited to 'scripts') diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 8b7dcb71..36180633 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -22,7 +22,15 @@ RUN apt-get -y install python-srp RUN apt-get -y install python-scrypt RUN apt-get -y install leap-keymanager RUN apt-get -y install python-tz + +# soledad-perf deps +RUN pip install klein +RUN apt-get -y install gnuplot RUN apt-get -y install curl +RUN apt-get -y install httperf + +# debugging deps +RUN apt-get -y install vim RUN apt-get -y install python-ipdb # copy over files to help setup the environment and run soledad @@ -34,10 +42,11 @@ COPY files/setup-env.sh /usr/local/soledad/ RUN /usr/local/soledad/setup-env.sh # copy runtime files for running server, client, tests, etc on a container -COPY files/test-env.py /usr/local/soledad/ COPY files/client_side_db.py /usr/local/soledad/ -COPY files/util.py /usr/local/soledad/ -COPY files/start-server.sh /usr/local/soledad/ COPY files/start-client-test.sh /usr/local/soledad/ +COPY files/run-perf-test.sh /usr/local/soledad/ +COPY files/start-server.sh /usr/local/soledad/ COPY files/start-trial-test.sh /usr/local/soledad/ +COPY files/test-env.py /usr/local/soledad/ +COPY files/util.py /usr/local/soledad/ COPY files/conf/* /usr/local/soledad/conf/ diff --git a/scripts/docker/Makefile b/scripts/docker/Makefile index 872bdc40..41334142 100644 --- a/scripts/docker/Makefile +++ b/scripts/docker/Makefile @@ -12,17 +12,29 @@ # make run-server CONTAINER_ID_FILE=/tmp/container-id.txt # make run-client-test CONTAINER_ID_FILE=/tmp/container-id.txt +##################################################################### +# Some configurations you might override when calling this makefile # +##################################################################### -IMAGE_NAME ?= "leap/soledad:1.0" -SOLEDAD_REMOTE ?= "https://0xacab.org/leap/soledad.git" -SOLEDAD_BRANCH ?= "develop" +IMAGE_NAME ?= "leap/soledad:1.0" +SOLEDAD_REMOTE ?= "https://0xacab.org/leap/soledad.git" +SOLEDAD_BRANCH ?= "develop" +SOLEDAD_PRELOAD_NUM ?= "100" +SOLEDAD_PRELOAD_SIZE ?= "500" +############################################## +# Docker image generation (main make target) # +############################################## all: image image: docker build -t $(IMAGE_NAME) . +################################################## +# Run a Soledad Server inside a docker container # +################################################## + run-server: @if [ -z "$(CONTAINER_ID_FILE)" ]; then \ echo "Error: you have to pass a value to CONTAINER_ID_FILE."; \ @@ -31,6 +43,8 @@ run-server: docker run \ --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \ --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \ + --env="SOLEDAD_PRELOAD_NUM=$(SOLEDAD_PRELOAD_NUM)" \ + --env="SOLEDAD_PRELOAD_SIZE=$(SOLEDAD_PRELOAD_SIZE)" \ --cidfile=$(CONTAINER_ID_FILE) \ --detach \ $(IMAGE_NAME) \ @@ -50,6 +64,10 @@ run-client-test: $(IMAGE_NAME) \ /usr/local/soledad/start-client-test.sh +################################################# +# Run all trial tests inside a docker container # +################################################# + run-trial-test: docker run -t -i \ --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \ @@ -57,8 +75,49 @@ run-trial-test: $(IMAGE_NAME) \ /usr/local/soledad/start-trial-test.sh +############################################ +# Performance tests and graphic generation # +############################################ + +run-perf: + helper/run-test.sh perf + +run-perf-test: + @if [ -z "$(CONTAINER_ID_FILE)" ]; then \ + echo "Error: you have to pass a value to CONTAINER_ID_FILE."; \ + exit 2; \ + fi + container_id=`cat $(CONTAINER_ID_FILE)`; \ + server_ip=`./helper/get-container-ip.sh $${container_id}`; \ + docker run -t -i \ + --cidfile=$(CONTAINER_ID_FILE)-perf \ + --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \ + --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \ + --env="SOLEDAD_PERF_REMOTE=https://0xacab.org/drebs/soledad-perf.git" \ + --env="SOLEDAD_PERF_BRANCH=bug/ensure-events-server" \ + --env="SOLEDAD_PRELOAD_NUM=$(SOLEDAD_PRELOAD_NUM)" \ + --env="SOLEDAD_PRELOAD_SIZE=$(SOLEDAD_PRELOAD_SIZE)" \ + --env="SOLEDAD_STATS=1" \ + --env="SOLEDAD_SERVER_URL=http://$${server_ip}:2424" \ + $(IMAGE_NAME) \ + /usr/local/soledad/run-perf-test.sh + +cp-perf-result: + @if [ -z "$(CONTAINER_ID_FILE)" ]; then \ + echo "Error: you have to pass a value to CONTAINER_ID_FILE."; \ + exit 2; \ + fi + perf_id=`cat $(CONTAINER_ID_FILE)-perf`; \ + docker cp $${perf_id}:/var/local/soledad-perf/out/sync-stats.png /tmp/; \ + docker cp $${perf_id}:/var/local/soledad-perf/out/series.log /tmp/ + +######################## +# Other helper targets # +######################## + run-shell: image docker run -t -i $(IMAGE_NAME) /bin/bash rm-all-containers: - docker ps -a | cut -d" " -f 1 | tail -n +2 | xargs docker rm -f + containers=`docker ps -a | cut -d" " -f 1 | tail -n +2 | xargs`; \ + if [ ! -z ${containers} ]; then docker rm -f $${containers}; fi diff --git a/scripts/docker/TODO b/scripts/docker/TODO index 75d45a8e..5185d754 100644 --- a/scripts/docker/TODO +++ b/scripts/docker/TODO @@ -1,3 +1 @@ - limit resources of containers (mem and cpu) -- add a file to run tests inside container -- use server ip to run test diff --git a/scripts/docker/files/run-perf-test.sh b/scripts/docker/files/run-perf-test.sh new file mode 100755 index 00000000..80138b2a --- /dev/null +++ b/scripts/docker/files/run-perf-test.sh @@ -0,0 +1,124 @@ +#!/bin/sh + +# Start a soledad-perf test using a remote server. +# +# The script does the following: +# +# - configure a remote repository for soledad repo if SOLEDAD_REMOTE is set. +# +# - checkout a specific branch if SOLEDAD_BRANCH is set. +# +# - run the soledad-perf local twisted server that runs the client. Note +# that the actual soledad server should be running on another docker +# container. This local server is only used to measure responsiveness of +# soledad client. The script waits for the server to come up before +# continuing, or else times out after TIMEOUT seconds. +# +# - trigger the creation of documents for sync. +# +# - start the measurement of server responsiveness and sync stages. +# +# - stop the test. +# +# This script is meant to be copied to the docker container and run upon +# container start. + +CMD="/usr/local/soledad/test-env.py" +REPO="/var/local/soledad" +TIMEOUT=20 + +#----------------------------------------------------------------------------- +# configure a remote and checkout a branch +#----------------------------------------------------------------------------- + +if [ ! -z "${SOLEDAD_REMOTE}" ]; then + git -C ${REPO} remote add test ${SOLEDAD_REMOTE} + git -C ${REPO} fetch test +fi + +if [ ! -z "${SOLEDAD_BRANCH}" ]; then + git -C ${REPO} checkout ${SOLEDAD_BRANCH} +fi + +if [ ! -z "${SOLEDAD_PERF_REMOTE}" ]; then + git -C /var/local/soledad-perf remote add test ${SOLEDAD_PERF_REMOTE} + git -C /var/local/soledad-perf fetch test +fi + +if [ ! -z "${SOLEDAD_PERF_BRANCH}" ]; then + git -C /var/local/soledad-perf checkout ${SOLEDAD_PERF_BRANCH} +fi + +#----------------------------------------------------------------------------- +# write a configuration file for the perf test +#----------------------------------------------------------------------------- + +cd /var/local/soledad-perf + +cat > defaults.conf < /dev/null & +sleep 5 # wait a bit for some data points + +# run a sync and generate a graph +make trigger-sync +make trigger-stop +make graph-image diff --git a/scripts/docker/files/start-server.sh b/scripts/docker/files/start-server.sh index 7493930a..b9b5e4ad 100755 --- a/scripts/docker/files/start-server.sh +++ b/scripts/docker/files/start-server.sh @@ -2,10 +2,28 @@ # Start a soledad server inside a docker container. # +# This script will: +# +# - eventually checkout a specific branch from a specific soledad remote. +# +# - create everything a soledad server needs to run (certificate, backend +# server database, tables, etc. +# +# - eventually preload the server database with a number of documents equal +# to SOLEDAD_PRELOAD_NUM, and with payload size equal to +# SOLEDAD_PRELOAD_SIZE. +# +# - run the soledad server. +# # This script is meant to be copied to the docker container and run upon # container start. CMD="/usr/local/soledad/test-env.py" + +#--------------------------------------------------------------------------- +# eventually checkout a specific branch from a specific remote +#--------------------------------------------------------------------------- + REPO="/var/local/soledad" if [ ! -z "${SOLEDAD_REMOTE}" ]; then @@ -17,10 +35,49 @@ if [ ! -z "${SOLEDAD_BRANCH}" ]; then git -C ${REPO} checkout ${SOLEDAD_BRANCH} fi +#--------------------------------------------------------------------------- +# setup environment for running soledad server +#--------------------------------------------------------------------------- + ${CMD} couch start ${CMD} user-db create ${CMD} token-db create ${CMD} token-db insert-token ${CMD} shared-db create ${CMD} cert create + +#--------------------------------------------------------------------------- +# write a configuration file for the perf test +#--------------------------------------------------------------------------- + +if [ "${SOLEDAD_PRELOAD_NUM}" -gt 0 ]; then + cd /var/local/soledad-perf + + cat > defaults.conf <