Skip to content

Commit 2970bc6

Browse files
authored
ci(benchmarks): fix high memory usage in span + otelspan (#15200)
## Description These benchmarks were using like 900+ mb of RSS. In the case when we don't finish the spans, the way we were clearing the spans was in an un-optimal place, since we would build up all created spans across all loops in memory and then at the end clear them. This clears them after every loop, so each loops/max memory usage is only the max memory for that specific loop. ## Testing <!-- Describe your testing strategy or note what tests are included --> ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> ## Additional Notes <!-- Any other information that would be helpful for reviewers -->
1 parent d44ad4b commit 2970bc6

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

.gitlab/benchmarks/bp-runner.microbenchmarks.fail-on-breach.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,11 @@ experiments:
799799
- name: otelspan-add-metrics
800800
thresholds:
801801
- execution_time < 344.80 ms
802-
- max_rss_usage < 675.00 MB
802+
- max_rss_usage < 47.50 MB
803803
- name: otelspan-add-tags
804804
thresholds:
805805
- execution_time < 314.00 ms
806-
- max_rss_usage < 675.00 MB
806+
- max_rss_usage < 47.50 MB
807807
- name: otelspan-get-context
808808
thresholds:
809809
- execution_time < 92.35 ms
@@ -1032,11 +1032,11 @@ experiments:
10321032
- name: span-add-metrics
10331033
thresholds:
10341034
- execution_time < 93.50 ms
1035-
- max_rss_usage < 961.00 MB
1035+
- max_rss_usage < 53.00 MB
10361036
- name: span-add-tags
10371037
thresholds:
10381038
- execution_time < 155.00 ms
1039-
- max_rss_usage < 962.50 MB
1039+
- max_rss_usage < 53.00 MB
10401040
- name: span-get-context
10411041
thresholds:
10421042
- execution_time < 20.50 ms

benchmarks/otel_span/scenario.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ def _(loops):
9292
if finishspan:
9393
s.end()
9494

95-
# If we are finishing spans, we need to ensure that the span aggregator is cleared
96-
# to avoid memory leaks and errors on shutdown
97-
if not finishspan:
98-
if hasattr(tracer, "_span_aggregator"):
99-
if hasattr(tracer._span_aggregator, "_traces"):
100-
tracer._span_aggregator._traces.clear()
95+
# If we are finishing spans, we need to ensure that the span aggregator is cleared
96+
# to avoid memory leaks and errors on shutdown
97+
# DEV: Do this per-loop to keep memory usage lower during the test
98+
if not finishspan:
99+
if hasattr(tracer, "_span_aggregator"):
100+
if hasattr(tracer._span_aggregator, "_traces"):
101+
tracer._span_aggregator._traces.clear()
101102

102103
yield _

benchmarks/span/scenario.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ def _(loops):
8484
if finishspan:
8585
s.finish()
8686

87-
# If we are finishing spans, we need to ensure that the span aggregator is cleared
88-
# to avoid memory leaks and errors on shutdown
89-
if not finishspan:
90-
if hasattr(tracer, "_span_aggregator"):
91-
if hasattr(tracer._span_aggregator, "_traces"):
92-
tracer._span_aggregator._traces.clear()
87+
# If we are finishing spans, we need to ensure that the span aggregator is cleared
88+
# to avoid memory leaks and errors on shutdown
89+
# DEV: Do this per-loop to keep memory usage lower during the test
90+
if not finishspan:
91+
if hasattr(tracer, "_span_aggregator"):
92+
if hasattr(tracer._span_aggregator, "_traces"):
93+
tracer._span_aggregator._traces.clear()
9394

9495
yield _

0 commit comments

Comments
 (0)