Skip to content

Commit 3555677

Browse files
[python_many_threads] Reduce noise in wall time (#142)
1 parent 518c633 commit 3555677

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

scenarios/python_many_threads/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WORKDIR /app
1010

1111
RUN pip install -r requirements.txt
1212

13-
ENV EXECUTION_TIME_SEC="30"
13+
ENV EXECUTION_TIME_SEC="60"
1414

1515
ENV DD_PROFILING_ENABLED="true"
1616

@@ -26,4 +26,7 @@ ENV _DD_PROFILING_STACK_MAX_THREADS="5"
2626
ENV _DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED=1
2727
ENV _DD_PROFILING_STACK_ADAPTIVE_SAMPLING_MAX_INTERVAL_US="10000"
2828

29+
# Make sure we don't upload around the one minute mark.
30+
ENV DD_PROFILING_UPLOAD_INTERVAL=120
31+
2932
CMD python main.py

scenarios/python_many_threads/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,24 @@ def worker(barrier: threading.Barrier, end: float) -> None:
1919

2020
if __name__ == "__main__":
2121
prof = Profiler()
22-
prof.start()
2322

2423
execution_time = float(os.environ.get("EXECUTION_TIME_SEC", "30"))
2524
end = time() + execution_time
2625

27-
barrier = threading.Barrier(NUM_WORKERS)
26+
barrier = threading.Barrier(NUM_WORKERS + 1)
2827
threads: list[threading.Thread] = [
2928
threading.Thread(target=worker, args=(barrier, end), name=f"worker-{i}") for i in range(NUM_WORKERS)
3029
]
3130

3231
for t in threads:
3332
t.start()
3433

34+
prof.start()
35+
36+
# Every worker is now alive and parked on the barrier, so the profiler has
37+
# registered all 20 threads before any work begins. Release them together
38+
# so no thread misses early sampling cycles.
39+
barrier.wait()
40+
3541
for t in threads:
3642
t.join()

0 commit comments

Comments
 (0)