File tree Expand file tree Collapse file tree 5 files changed +126
-0
lines changed
scenarios/python_uwsgi_3.11 Expand file tree Collapse file tree 5 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 1+ ARG BASE_IMAGE="prof-python-3.11"
2+ FROM $BASE_IMAGE
3+
4+ # Copy the Python target into the container
5+ COPY ./scenarios/python_uwsgi_3.11/requirements.txt /app/
6+ RUN chmod 644 /app/*
7+
8+ # Set the working directory to the location of the program
9+ WORKDIR /app
10+
11+ RUN pip install -r requirements.txt
12+
13+ COPY ./scenarios/python_uwsgi_3.11/app.py /app/
14+ COPY ./scenarios/python_uwsgi_3.11/uwsgi.ini /app/
15+
16+ ENV DD_TRACE_ENABLED=false
17+ ENV DD_PROFILING_ENABLED=true
18+ ENV DD_TRACE_DEBUG=false
19+ ENV DD_PROFILING_UPLOAD_INTERVAL=3
20+ ENV _DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED=0
21+ ENV DD_PROFILING_OUTPUT_PPROF="/app/data/profiles"
22+ ENV EXECUTION_TIME_SEC=10
23+
24+ # Run the program when the container starts
25+ CMD ["uwsgi" , "--ini" , "uwsgi.ini" ]
Original file line number Diff line number Diff line change 1+ import os
2+ import signal
3+ import time
4+ from collections .abc import Callable
5+ from threading import Thread
6+
7+ import requests
8+ import uwsgi # pyright: ignore[reportMissingModuleSource]
9+
10+
11+ def _make_requests () -> None :
12+ run_time = int (os .environ .get ("EXECUTION_TIME_SEC" , 10 ))
13+
14+ start = time .monotonic ()
15+ while time .monotonic () - start < run_time :
16+ try :
17+ print (f"Requester PID: { os .getpid ()} requesting" )
18+ requests .get ("http://localhost:8000" , timeout = 1 )
19+ except Exception as e : # noqa: PERF203,BLE001
20+ print (e )
21+
22+ time .sleep (1.0 )
23+
24+ # Ask the master process to exit
25+ try :
26+ os .kill (uwsgi .masterpid (), signal .SIGINT )
27+ finally :
28+ pass
29+
30+
31+ def compute_big_number () -> int :
32+ x = 0
33+ for i in range (1_000_000 ):
34+ x *= i
35+ return x
36+
37+
38+ def application (environ : dict , start_response : Callable ) -> list [bytes ]: # noqa: ARG001 # pyright: ignore[reportUnusedParameter]
39+ x = compute_big_number ()
40+ start_response ("200 OK" , [("Content-Type" , "text/plain" )])
41+ return [f"Hello, World! { x } " .encode ()]
42+
43+
44+ Thread (target = _make_requests , daemon = True , name = "Requester" ).start ()
Original file line number Diff line number Diff line change 1+ {
2+ "test_name" : " python_uwsgi_3.11" ,
3+ "scale_by_duration" : true ,
4+ "pprof-regex" : " " ,
5+ "stacks" : [
6+ {
7+ "profile-type" : " wall-time" ,
8+ "pprof-regex" : " " ,
9+ "stack-content" : [
10+ {
11+ "regular_expression" : " .*_make_requests.*" ,
12+ "percent" : 33 ,
13+ "error_margin" : 5 ,
14+ "labels" : [
15+ {
16+ "key" : " thread name" ,
17+ "values" : [
18+ " Requester"
19+ ]
20+ }
21+ ]
22+ }
23+ ]
24+ },
25+ {
26+ "profile-type" : " wall-time" ,
27+ "pprof-regex" : " " ,
28+ "stack-content" : [
29+ {
30+ "regular_expression" : " .*application;compute_big_number.*" ,
31+ "percent" : 30 ,
32+ "error_margin" : 7
33+ }
34+ ]
35+ }
36+ ]
37+ }
Original file line number Diff line number Diff line change 1+ ddtrace
2+ requests
3+ uwsgi
Original file line number Diff line number Diff line change 1+ [uwsgi]
2+ worker-reload-mercy = 3
3+ harakiri = 0
4+ harakiri-graceful-timeout = 3
5+ py-call-osafterfork = true
6+
7+ module = app:application
8+ http = 127.0.0.1:8000
9+
10+ master = true
11+ processes = 3
12+
13+ ; ; ddtrace required options
14+ enable-threads = 1
15+ lazy-apps = 1
16+ skip-atexit = 1 ; For uwsgi<2.0.30
17+ import =ddtrace.bootstrap.sitecustomize
You can’t perform that action at this time.
0 commit comments