Skip to content

Commit be4a35e

Browse files
majorgreysP403n1x87crysmagsbrettlangdon
authored
feat(performance): add simple django scenario (#2553)
* feat(performance): add django-simple scenario * fix ddtrace version install * Update benchmarks/docker/django_simple/start Co-authored-by: Gabriele N. Tornetta <[email protected]> * Update benchmarks/docker/django_simple/start Co-authored-by: Gabriele N. Tornetta <[email protected]> * fixes * add profiler variant * doc update * move out of docker dir * profiling, statsd, summary * add tracer+profiler variant * major rework with sirun and jq for summary * major rework with sirun and jq for summary * fewer sirun iterations * fix profiler variant * cleanup * use yaml config for sirun Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: crysmags <[email protected]> Co-authored-by: Brett Langdon <[email protected]>
1 parent 6ef024a commit be4a35e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1790
-0
lines changed

benchmarks/__init__.py

Whitespace-only changes.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
ARG PYTHON_VERSION=3.9-slim-buster
2+
3+
# define an alias for the specfic python version used in this file.
4+
FROM python:${PYTHON_VERSION} as python
5+
6+
# Python build stage
7+
FROM python as python-build-stage
8+
9+
# Install apt packages
10+
RUN apt-get update && apt-get install --no-install-recommends -y \
11+
# dependencies for building Python packages
12+
build-essential \
13+
# need git for pip installs
14+
git
15+
16+
# Requirements are installed here to ensure they will be cached.
17+
COPY ./requirements.txt .
18+
19+
# Create Python Dependency and Sub-Dependency Wheels.
20+
RUN pip wheel --wheel-dir /usr/src/app/wheels \
21+
-r requirements.txt
22+
23+
# Python 'run' stage
24+
FROM python as python-run-stage
25+
26+
ARG APP_HOME=/app
27+
28+
ENV PYTHONUNBUFFERED 1
29+
ENV PYTHONDONTWRITEBYTECODE 1
30+
31+
WORKDIR ${APP_HOME}
32+
33+
RUN addgroup --system django \
34+
&& adduser --system --ingroup django django
35+
36+
# Install required system dependencies
37+
RUN apt-get update && apt-get install --no-install-recommends -y \
38+
# Translations dependencies
39+
gettext \
40+
# other dependencies
41+
procps \
42+
curl \
43+
# dependencies for installing Python packages from git
44+
build-essential \
45+
git \
46+
# cleaning up unused files
47+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
48+
&& rm -rf /var/lib/apt/lists/*
49+
50+
# All absolute dir copies ignore workdir instruction. All relative dir copies are wrt to the workdir instruction
51+
# copy python dependency wheels from python-build-stage
52+
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
53+
54+
# sirun
55+
RUN curl -sL https://github.com/DataDog/sirun/releases/download/v0.1.8/sirun-v0.1.8-x86_64-unknown-linux-gnu.tar.gz | tar zxf - -C /tmp && mv /tmp/sirun /usr/bin
56+
57+
# k6
58+
RUN curl -SL https://github.com/k6io/k6/releases/download/v0.32.0/k6-v0.32.0-linux-amd64.tar.gz | tar zxf - -C /tmp && mv /tmp/k6-v0.32.0-linux-amd64/k6 /usr/bin
59+
60+
# jq
61+
RUN curl -L -o /usr/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && \
62+
chmod +x /usr/bin/jq
63+
64+
# copy application code to WORKDIR
65+
COPY --chown=django:django . ${APP_HOME}
66+
67+
# make django owner of the WORKDIR directory as well.
68+
RUN chown django:django ${APP_HOME}
69+
70+
# top level directory for artifacts
71+
ARG ARTIFACTS=/artifacts
72+
RUN mkdir -p ${ARTIFACTS}
73+
RUN chown django:django ${ARTIFACTS}
74+
75+
USER django
76+
77+
# Create venv
78+
ENV VIRTUAL_ENV=/app/venv
79+
RUN python3 -m venv $VIRTUAL_ENV
80+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
81+
82+
# use wheels to install python dependencies
83+
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/*
84+
85+
# Run migrations in image creation as data will not change during run
86+
RUN python /app/manage.py collectstatic --noinput \
87+
&& python /app/manage.py migrate
88+
89+
# For performance testing
90+
ENV DDTRACE_GIT_COMMIT_ID ""
91+
ENV DDTRACE_WHEELS ""
92+
ENV WEB_CONCURRENCY 1
93+
ENV SIRUN_NO_STDIO 0
94+
ENV K6_STATSD_ENABLE_TAGS "true"
95+
96+
ENTRYPOINT ["/app/entrypoint"]
97+
CMD ["/app/benchmark"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Simple Django Performance Scenario
2+
==================================
3+
4+
This application image uses a simple Django application for performance testing ``ddtrace``.
5+
6+
Build
7+
-----
8+
9+
Use docker to build the image which will run tests and store output in an artifacts directory::
10+
11+
docker build -t django_simple benchmarks/django_simple/
12+
13+
Run
14+
---
15+
16+
To run, execute::
17+
18+
docker run -it --rm django_simple
19+
20+
If you want to save the output, mount a volume to ``/app/output``::
21+
22+
docker run -it --rm -v "/path/to/output":"/artifacts/output" django_simple
23+
24+
This image will by default install the release version of ``ddtrace``.
25+
26+
You can install a different version by using git tags or commit hashes as the value for the ``DDTRACE_GIT_COMMIT_ID`` environment variable::
27+
28+
docker run -it --rm -e "DDTRACE_GIT_COMMIT_ID=v0.48.1" django_simple
29+
30+
You can also install from a set of wheel by mounting a volume with the necessary wheels and setting the ``DDTRACE_WHEELS`` environment variable::
31+
32+
docker run -it --rm -e "DDTRACE_WHEELS=/artifacts/wheels" -v "/path/to/wheels/":"/artifacts/wheels/" django_simple

benchmarks/django_simple/benchmark

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
mkdir -p /artifacts/output/
8+
9+
# cleanup any existing output artifacts
10+
rm -f /artifacts/output/*.*
11+
12+
sirun meta.yaml | tee /artifacts/output/sirun.ndjson
13+
14+
jq -s -f summarize_sirun.jq /artifacts/output/sirun.ndjson | tee /artifacts/output/summary_sirun.json
15+
jq -s -f summarize_k6.jq /artifacts/output/k6.ndjson | tee /artifacts/output/summary_k6.json
16+
17+
# keep process alive before exiting
18+
# FIXME: remove once artifacts can be uploaded when run in CI
19+
sleep 30m

benchmarks/django_simple/config/__init__.py

Whitespace-only changes.

benchmarks/django_simple/config/settings/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)