diff --git a/.github/workflows/django-overhead-profile.yml b/.github/workflows/django-overhead-profile.yml index 55f023f0c8f..6d026338ca9 100644 --- a/.github/workflows/django-overhead-profile.yml +++ b/.github/workflows/django-overhead-profile.yml @@ -26,6 +26,7 @@ jobs: DD_PROFILING_ENABLED: "1" DD_PROFILING_STACK_V2_ENABLED: ${{ matrix.stack_v2 }} DD_PROFILING_OUTPUT_PPROF: ${{ github.workspace }}/prefix/artifacts/ddtrace_profile + DD_EXCEPTION_REPLAY_ENABLED: "1" defaults: run: working-directory: ddtrace diff --git a/scripts/profiles/django-simple/k6-exc.js b/scripts/profiles/django-simple/k6-exc.js new file mode 100644 index 00000000000..106652037bc --- /dev/null +++ b/scripts/profiles/django-simple/k6-exc.js @@ -0,0 +1,10 @@ +import http from 'k6/http'; + +export const options = { + duration: '60s', + vus: 100, +}; + +export default function () { + const res = http.get('http://127.0.0.1:8080/polls/123/results/'); +} diff --git a/scripts/profiles/django-simple/k6-load.js b/scripts/profiles/django-simple/k6-load.js index 5439e80ea16..9e09f108e01 100644 --- a/scripts/profiles/django-simple/k6-load.js +++ b/scripts/profiles/django-simple/k6-load.js @@ -1,5 +1,4 @@ import http from 'k6/http'; -import { sleep } from 'k6'; export const options = { duration: '60s', @@ -7,5 +6,5 @@ export const options = { }; export default function () { - const res = http.get('http://127.0.0.1:8000/accounts/signup/'); + const res = http.get('http://127.0.0.1:8080/polls/123/vote/'); } diff --git a/scripts/profiles/django-simple/run.sh b/scripts/profiles/django-simple/run.sh index 109f6b30c51..fcfbbf9bfe6 100755 --- a/scripts/profiles/django-simple/run.sh +++ b/scripts/profiles/django-simple/run.sh @@ -9,59 +9,83 @@ AUSTIN_EXPOSURE=5 # sec test -f ${PREFIX}/gunicorn.pid && (kill -9 `cat ${PREFIX}/gunicorn.pid` ; sleep 3) || rm -f ${PREFIX}/gunicorn.pid pkill k6 || true -test -d ${PREFIX}/artifacts && rm -rf ${PREFIX}/artifacts || mkdir -p ${PREFIX}/artifacts +pkill -9 -f uwsgi || true +test -d ${PREFIX}/artifacts && rm -rf ${PREFIX}/artifacts +mkdir -p ${PREFIX}/artifacts sudo echo "sudo OK" +sudo rm -f ${PREFIX}/uwsgi.pid + function profile_with_load { name=${1} + scenario=${2} + + echo "- profiling for ${name}" sleep 3 - ${PREFIX}/k6*/k6 run --quiet scripts/profiles/django-simple/k6-load.js & + echo "Starting load" + ${PREFIX}/k6*/k6 run --quiet scripts/profiles/django-simple/k6-${scenario}.js & sleep 2 - sudo `which austin` -bsCi ${AUSTIN_INTERVAL} -o ${PREFIX}/artifacts/${name}.mojo -p `cat ${PREFIX}/gunicorn.pid` -x ${AUSTIN_EXPOSURE} - LC_ALL=C sed -i 's|/home/runner/work/dd-trace-py/dd-trace-py/ddtrace/||g' ${PREFIX}/artifacts/${name}.mojo + echo "Attaching Austin to $(cat ${PREFIX}/uwsgi.pid)" + sudo `which austin` -bsCi ${AUSTIN_INTERVAL} -o ${PREFIX}/artifacts/${scenario}_${name}.mojo -p `cat ${PREFIX}/uwsgi.pid` -x ${AUSTIN_EXPOSURE} + LC_ALL=C sed -i 's|/home/runner/work/dd-trace-py/dd-trace-py/ddtrace/||g' ${PREFIX}/artifacts/${scenario}_${name}.mojo + echo "Stopping load" pkill k6 } source ${PREFIX}/bin/activate -export DJANGO_SETTINGS_MODULE="config.settings.production" -export DJANGO_ALLOWED_HOSTS="127.0.0.1" -export DJANGO_SECRET_KEY="SECRET_KEY" export DATABASE_URL="sqlite:///django.db" +export DJANGO_ALLOWED_HOSTS="127.0.0.1" +export DEVELOPMENT_MODE=True # Tag traces with HTTP headers to benchmark the related code export DD_TRACE_HEADER_TAGS="User-Agent:http.user_agent,Referer:http.referer,Content-Type:http.content_type,Etag:http.etag" -# Baseline -pushd ${PREFIX}/trace-examples/python/django/django-simple - gunicorn config.wsgi --pid ${PREFIX}/gunicorn.pid > /dev/null & - echo "Done" -popd -profile_with_load "baseline" -kill $(cat ${PREFIX}/gunicorn.pid) - -pushd ${PREFIX}/trace-examples/python/django/django-simple - ddtrace-run gunicorn config.wsgi --pid ${PREFIX}/gunicorn.pid > /dev/null & -popd -profile_with_load "head" -kill $(cat ${PREFIX}/gunicorn.pid) - -sudo chown -R $(id -u):$(id -g) ${PREFIX}/artifacts/* - -echo -n "Converting MOJO to Austin ... " -mojo2austin ${PREFIX}/artifacts/head.mojo ${PREFIX}/artifacts/head.austin.tmp -mojo2austin ${PREFIX}/artifacts/baseline.mojo ${PREFIX}/artifacts/baseline.austin.tmp -echo "[done]" - -echo -n "Diffing ... " -python scripts/diff.py \ - ${PREFIX}/artifacts/head.austin.tmp \ - ${PREFIX}/artifacts/baseline.austin.tmp \ - ${PREFIX}/artifacts/baseline_head.diff -echo "[done]" - -rm ${PREFIX}/artifacts/*.austin.tmp - -head -n 25 ${PREFIX}/artifacts/baseline_head.diff.top + +function run_scenario { + scenario=${1} + + echo "Running scenario ${scenario}" + + # Baseline + pushd ${PREFIX}/trace-examples/python/django/sample-django + uwsgi --http :8080 --enable-threads --module mysite.wsgi --pidfile ${PREFIX}/uwsgi.pid 2> /dev/null & + echo "Done" + popd + profile_with_load "baseline" ${scenario} + echo "Stopping uwsgi" + uwsgi --stop ${PREFIX}/uwsgi.pid + pkill -9 -f uwsgi || true + + pushd ${PREFIX}/trace-examples/python/django/sample-django + uwsgi --http :8080 --enable-threads --module mysite.wsgi --pidfile ${PREFIX}/uwsgi.pid --import=ddtrace.bootstrap.sitecustomize 2> /dev/null & + popd + profile_with_load "head" ${scenario} + echo "Stopping uwsgi" + uwsgi --stop ${PREFIX}/uwsgi.pid + pkill -9 -f uwsgi || true + + sudo chown -R $(id -u):$(id -g) ${PREFIX}/artifacts/* + + echo -n "Converting MOJO to Austin ... " + mojo2austin ${PREFIX}/artifacts/${scenario}_head.mojo ${PREFIX}/artifacts/${scenario}_head.austin.tmp + mojo2austin ${PREFIX}/artifacts/${scenario}_baseline.mojo ${PREFIX}/artifacts/${scenario}_baseline.austin.tmp + echo "[done]" + + echo -n "Diffing ... " + python scripts/diff.py \ + ${PREFIX}/artifacts/${scenario}_head.austin.tmp \ + ${PREFIX}/artifacts/${scenario}_baseline.austin.tmp \ + ${PREFIX}/artifacts/${scenario}_baseline_head.diff + echo "[done]" + + rm ${PREFIX}/artifacts/*.austin.tmp + + head -n 25 ${PREFIX}/artifacts/${scenario}_baseline_head.diff.top +} + + +run_scenario "load" +run_scenario "exc" diff --git a/scripts/profiles/django-simple/setup.sh b/scripts/profiles/django-simple/setup.sh index cc6c20e9a03..2f14db6ee4d 100755 --- a/scripts/profiles/django-simple/setup.sh +++ b/scripts/profiles/django-simple/setup.sh @@ -6,9 +6,7 @@ PREFIX=${1} AUSTIN_VERSION="3.6" K6_VERSION="0.26.2" -export DJANGO_SETTINGS_MODULE="config.settings.production" export DJANGO_ALLOWED_HOSTS="127.0.0.1" -export DJANGO_SECRET_KEY="SECRET_KEY" export DATABASE_URL="sqlite:///django.db" # Clean up existing installation @@ -26,12 +24,12 @@ source ${PREFIX}/bin/activate pip install pip --upgrade # Install the application -git clone https://github.com/DataDog/trace-examples.git ${PREFIX}/trace-examples +test -d ${PREFIX}/trace-examples || git clone -b sample-django --single-branch https://github.com/DataDog/trace-examples.git ${PREFIX}/trace-examples pushd ${PREFIX}/trace-examples/ - git checkout origin/django-simple - pushd python/django/django-simple - pip install -r requirements/production.txt + pushd python/django/sample-django + pip install -r requirements.txt python manage.py migrate + python manage.py collectstatic popd popd