File tree Expand file tree Collapse file tree 5 files changed +125
-0
lines changed
scenarios/python_uwsgi_3.11 Expand file tree Collapse file tree 5 files changed +125
-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_TRACE_DEBUG=false
18+ ENV DD_PROFILING_UPLOAD_INTERVAL=3
19+ ENV _DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED=0
20+ ENV DD_PROFILING_OUTPUT_PPROF="/app/data/profiles"
21+
22+ # Run the program when the container starts
23+ 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+ from ddtrace .profiling import Profiler
10+
11+ profiler = Profiler ()
12+ profiler .start ()
13+
14+
15+ def _make_requests () -> None :
16+ start = time .monotonic ()
17+ while time .monotonic () - start < 10.0 :
18+ try :
19+ print (f"Requester PID: { os .getpid ()} requesting" )
20+ requests .get ("http://localhost:8000" , timeout = 1 )
21+ except Exception as e : # noqa: PERF203,BLE001
22+ print (e )
23+
24+ time .sleep (1.0 )
25+
26+ # Ask the master process to exit
27+ try :
28+ os .kill (uwsgi .masterpid (), signal .SIGINT )
29+ finally :
30+ pass
31+
32+
33+ def compute_big_number () -> int :
34+ x = 0
35+ for i in range (1_000_000 ):
36+ x += i
37+ return x
38+
39+
40+ def application (environ : dict , start_response : Callable ) -> list [bytes ]: # noqa: ARG001
41+ x = compute_big_number ()
42+ start_response ("200 OK" , [("Content-Type" , "text/plain" )])
43+ return [f"Hello, World! { x } " .encode ()]
44+
45+
46+ 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" : false ,
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" : 33 ,
32+ "error_margin" : 5
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 = 3
4+ harakiri-graceful-timeout = 3
5+
6+ module = app:application
7+ http = 127.0.0.1:8000
8+
9+ master = true
10+ processes = 3
11+
12+ ; ; ddtrace required options
13+ enable-threads = 1
14+ lazy-apps = 1
15+ skip-atexit = 1 ; For uwsgi<2.0.30
16+ import =ddtrace.bootstrap.sitecustomize
You can’t perform that action at this time.
0 commit comments