Skip to content

Commit 1446531

Browse files
feat(perf): add base for scenarios (#2690)
* feat(perf): add base for scenarios * Update benchmarks/README.rst Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: Brett Langdon <[email protected]>
1 parent a2705f0 commit 1446531

File tree

12 files changed

+62
-118
lines changed

12 files changed

+62
-118
lines changed

benchmarks/README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Performance Testing
44
New scenario
55
------------
66

7-
Copy ``sample`` directory and edit the ``meta.yaml`` file to specify the executable. Add any additional requirements to the ``requirements.txt``.
7+
Create a new directory for a scenario which includes a ``scenario.py`` script to be run. Add any additional dependencies in a ``requirements_scenario.txt``.
88

9-
Build image::
9+
First you need to build the scenario image::
1010

11-
docker build -t benchmark-<scenario> --build-arg BENCHMARK=<scenario> -f base.Dockerfile .
11+
docker build -t perf-<scenario> --build-arg SCENARIO=<scenario> -f base/Dockerfile .
1212

13-
Run scenario::
13+
You can now run the scenario image with two versions of the library. The environment variables ``DDTRACE_INSTALL_{V1,V2}`` can be set to a PEP 508 specification or a git url:
1414

15-
docker run -it --rm benchmark-<scenario>
15+
docker run -it --rm -e DDTRACE_INSTALL_V1="ddtrace" -e DDTRACE_INSTALL_V2="ddtrace==0.50.0" perf-<scenario>
16+
docker run -it --rm -e DDTRACE_INSTALL_V1=git+https://github.com/Datadog/dd-trace-py@master -e DDTRACE_INSTALL_V2=git+https://github.com/Datadog/[email protected] perf-<scenario>

benchmarks/base.Dockerfile renamed to benchmarks/base/Dockerfile

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ ARG PYTHON_VERSION=3.9-slim-buster
22

33
FROM python:${PYTHON_VERSION} as python
44

5-
ARG BENCHMARK=sample
6-
ARG ARTIFACTS=/artifacts
5+
ARG SCENARIO=base
76

87
ENV PYTHONUNBUFFERED 1
98
ENV PYTHONDONTWRITEBYTECODE 1
@@ -22,27 +21,22 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
2221
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
2322
&& rm -rf /var/lib/apt/lists/*
2423

25-
# sirun
26-
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
24+
# Add base common files used by all scenarios
25+
COPY ./base/ /app/
2726

28-
COPY ./common/entrypoint /app/
29-
COPY ./common/benchmark /app/
27+
# Add scenario code, overriding anything from base
28+
COPY ./${SCENARIO}/ /app/
3029

31-
# Add benchmark scenario code, overriding anything from common
32-
COPY ./${BENCHMARK}/ /app/
33-
34-
# Create venv
30+
# Create venv for scenario requirements (other than ddtrace)
3531
ENV VIRTUAL_ENV=/app/.venv
3632
RUN python3 -m venv $VIRTUAL_ENV
3733
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
38-
3934
RUN pip install -r requirements.txt
4035

41-
# For performance testing
42-
ENV DDTRACE_GIT_COMMIT_ID ""
43-
ENV RUN_ID ""
44-
ENV PIP_INSTALL_WHEELS ""
45-
ENV SIRUN_NO_STDIO 0
36+
# Use separate venvs for the two versions of the library being compared
37+
ENV VENV_DDTRACE_V1=/app/.venv_ddtrace_v1/
38+
ENV VENV_DDTRACE_V2=/app/.venv_ddtrace_v2/
39+
ENV SCENARIO=${SCENARIO}
4640

4741
ENTRYPOINT ["/app/entrypoint"]
4842
CMD ["/app/benchmark"]

benchmarks/base/benchmark

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
if [[ -z "${RUN_ID}" ]]; then
5+
export RUN_ID=$(uuidgen)
6+
fi
7+
8+
ARTIFACTS=/artifacts/${RUN_ID}/${SCENARIO}
9+
mkdir -p ${ARTIFACTS}
10+
RESULTS_V1=${ARTIFACTS}/${DDTRACE_V1}.json
11+
RESULTS_V2=${ARTIFACTS}/${DDTRACE_V2}.json
12+
13+
# append venvs with ddtrace to sys.path
14+
15+
PYTHONPATH=${VENV_DDTRACE_V1}/lib/python3.9/site-packages \
16+
python scenario.py \
17+
--copy-env \
18+
--fast \
19+
-o ${RESULTS_V1}
20+
21+
PYTHONPATH=${VENV_DDTRACE_V2}/lib/python3.9/site-packages \
22+
python scenario.py \
23+
--copy-env \
24+
--fast \
25+
-o ${RESULTS_V2}
26+
27+
pyperf compare_to --table ${RESULTS_V2} ${RESULTS_V1}

benchmarks/base/entrypoint

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
python3 -m venv ${VENV_DDTRACE_V1}
5+
source ${VENV_DDTRACE_V1}/bin/activate
6+
pip install ${DDTRACE_INSTALL_V1}
7+
export DDTRACE_V1=$(python -c "import ddtrace; print(ddtrace.__version__)")
8+
deactivate
9+
10+
python3 -m venv ${VENV_DDTRACE_V2}
11+
source ${VENV_DDTRACE_V2}/bin/activate
12+
pip install ${DDTRACE_INSTALL_V2}
13+
export DDTRACE_V2=$(python -c "import ddtrace; print(ddtrace.__version__)")
14+
deactivate
15+
16+
exec "$@"

benchmarks/base/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-r requirements_scenario.txt
2+
3+
pyperf

benchmarks/base/requirements_scenario.txt

Whitespace-only changes.

benchmarks/common/benchmark

Lines changed: 0 additions & 13 deletions
This file was deleted.

benchmarks/common/entrypoint

Lines changed: 0 additions & 18 deletions
This file was deleted.

benchmarks/common/util.jq

Lines changed: 0 additions & 17 deletions
This file was deleted.

benchmarks/encoder/benchmark

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)