Skip to content

Avoid creating new ContinuingScope if the top scope is already keeping the span alive#5739

Merged
mcculls merged 1 commit into
masterfrom
mcculls/reduce-scope-allocations
Aug 18, 2023
Merged

Avoid creating new ContinuingScope if the top scope is already keeping the span alive#5739
mcculls merged 1 commit into
masterfrom
mcculls/reduce-scope-allocations

Conversation

@mcculls

@mcculls mcculls commented Aug 18, 2023

Copy link
Copy Markdown
Contributor

What Does This Do

This PR avoids allocating a new ContinuingScope when the top of the scope stack is already keeping the same span alive as the continuation. Instead we increment the existing scope's reference count and cancel the continuation.

In other words instead of stacking another scope onto the stack for the same span, we collapse it into the existing scope.

The main difference is that we cancel the continuation immediately rather than when the scope finally closes, but I believe this is acceptable because the existing scope should already be keeping the trace alive - either by the span if it's on the original thread or by a different continuation (in the existing ContinuingScope) if it's on a different thread.

Motivation

Reduces the number of ContinuingScope allocations when using fork-join pools.

@mcculls mcculls changed the title [WIPAvoid creating new ContinuingScope if the top scope is already keepin… [WIP] Avoid creating new ContinuingScope if the top scope is already keepin… Aug 18, 2023
@mcculls mcculls changed the title [WIP] Avoid creating new ContinuingScope if the top scope is already keepin… [WIP] Avoid creating new ContinuingScope if the top scope is already keeping the span alive Aug 18, 2023
@mcculls mcculls added tag: do not merge Do not merge changes tag: performance Performance related changes labels Aug 18, 2023
@mcculls
mcculls force-pushed the mcculls/reduce-scope-allocations branch 2 times, most recently from 4c25425 to c08c8fc Compare August 18, 2023 13:11
@mcculls
mcculls force-pushed the mcculls/reduce-scope-allocations branch from c08c8fc to 5599c5a Compare August 18, 2023 13:26
@pr-commenter

pr-commenter Bot commented Aug 18, 2023

Copy link
Copy Markdown

Benchmarks

Startup

Parameters

Baseline Candidate
commit 1.20.0-SNAPSHOT~4663dd598c 1.20.0-SNAPSHOT~5599c5a44e
config baseline candidate
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
module Agent Agent
parent None None
variant appsec appsec

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 62 cases.

Startup time reports for petclinic
gantt
    title petclinic - global startup overhead: candidate=1.20.0-SNAPSHOT~5599c5a44e, baseline=1.20.0-SNAPSHOT~4663dd598c

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (991.377 ms) : 0, 991377
Total [baseline] (9.18 s) : 0, 9180274
Agent [candidate] (985.205 ms) : 0, 985205
Total [candidate] (9.119 s) : 0, 9118919
section appsec
Agent [baseline] (1.069 s) : 0, 1069471
Total [baseline] (9.26 s) : 0, 9260172
Agent [candidate] (1.07 s) : 0, 1070492
Total [candidate] (9.216 s) : 0, 9215598
section iast
Agent [baseline] (1.088 s) : 0, 1087633
Total [baseline] (9.39 s) : 0, 9389931
Agent [candidate] (1.097 s) : 0, 1097021
Total [candidate] (9.559 s) : 0, 9559279
section profiling
Agent [baseline] (1.156 s) : 0, 1155817
Total [baseline] (9.474 s) : 0, 9473902
Agent [candidate] (1.157 s) : 0, 1157186
Total [candidate] (9.409 s) : 0, 9409227
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 991.377 ms -
Agent appsec 1.069 s 78.094 ms (7.9%)
Agent iast 1.088 s 96.256 ms (9.7%)
Agent profiling 1.156 s 164.441 ms (16.6%)
Total tracing 9.18 s -
Total appsec 9.26 s 79.898 ms (0.9%)
Total iast 9.39 s 209.657 ms (2.3%)
Total profiling 9.474 s 293.628 ms (3.2%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 985.205 ms -
Agent appsec 1.07 s 85.288 ms (8.7%)
Agent iast 1.097 s 111.816 ms (11.3%)
Agent profiling 1.157 s 171.982 ms (17.5%)
Total tracing 9.119 s -
Total appsec 9.216 s 96.68 ms (1.1%)
Total iast 9.559 s 440.36 ms (4.8%)
Total profiling 9.409 s 290.308 ms (3.2%)
gantt
    title petclinic - break down per module: candidate=1.20.0-SNAPSHOT~5599c5a44e, baseline=1.20.0-SNAPSHOT~4663dd598c

    dateFormat X
    axisFormat %s
section tracing
BytebuddyAgent [baseline] (614.546 ms) : 0, 614546
BytebuddyAgent [candidate] (610.312 ms) : 0, 610312
GlobalTracer [baseline] (285.2 ms) : 0, 285200
GlobalTracer [candidate] (283.738 ms) : 0, 283738
AppSec [baseline] (50.475 ms) : 0, 50475
AppSec [candidate] (50.304 ms) : 0, 50304
Remote Config [baseline] (660.927 µs) : 0, 661
Remote Config [candidate] (653.388 µs) : 0, 653
Telemetry [baseline] (6.055 ms) : 0, 6055
Telemetry [candidate] (5.992 ms) : 0, 5992
section appsec
BytebuddyAgent [baseline] (610.221 ms) : 0, 610221
BytebuddyAgent [candidate] (610.92 ms) : 0, 610920
GlobalTracer [baseline] (283.099 ms) : 0, 283099
GlobalTracer [candidate] (283.851 ms) : 0, 283851
AppSec [baseline] (135.361 ms) : 0, 135361
AppSec [candidate] (135.122 ms) : 0, 135122
Remote Config [baseline] (765.694 µs) : 0, 766
Remote Config [candidate] (724.165 µs) : 0, 724
Telemetry [baseline] (5.729 ms) : 0, 5729
Telemetry [candidate] (5.694 ms) : 0, 5694
section iast
BytebuddyAgent [baseline] (715.72 ms) : 0, 715720
BytebuddyAgent [candidate] (722.29 ms) : 0, 722290
GlobalTracer [baseline] (270.386 ms) : 0, 270386
GlobalTracer [candidate] (272.691 ms) : 0, 272691
AppSec [baseline] (46.922 ms) : 0, 46922
AppSec [candidate] (47.021 ms) : 0, 47021
Remote Config [baseline] (559.092 µs) : 0, 559
Remote Config [candidate] (560.361 µs) : 0, 560
Telemetry [baseline] (5.845 ms) : 0, 5845
Telemetry [candidate] (5.845 ms) : 0, 5845
IAST [baseline] (13.901 ms) : 0, 13901
IAST [candidate] (14.015 ms) : 0, 14015
section profiling
BytebuddyAgent [baseline] (622.521 ms) : 0, 622521
BytebuddyAgent [candidate] (623.176 ms) : 0, 623176
GlobalTracer [baseline] (348.503 ms) : 0, 348503
GlobalTracer [candidate] (348.955 ms) : 0, 348955
AppSec [baseline] (49.313 ms) : 0, 49313
AppSec [candidate] (48.963 ms) : 0, 48963
Remote Config [baseline] (660.829 µs) : 0, 661
Remote Config [candidate] (654.596 µs) : 0, 655
Telemetry [baseline] (5.998 ms) : 0, 5998
Telemetry [candidate] (5.919 ms) : 0, 5919
ProfilingAgent [baseline] (76.033 ms) : 0, 76033
ProfilingAgent [candidate] (76.638 ms) : 0, 76638
Profiling [baseline] (76.057 ms) : 0, 76057
Profiling [candidate] (76.662 ms) : 0, 76662
Loading
Startup time reports for insecure-bank
gantt
    title insecure-bank - global startup overhead: candidate=1.20.0-SNAPSHOT~5599c5a44e, baseline=1.20.0-SNAPSHOT~4663dd598c

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (991.533 ms) : 0, 991533
Total [baseline] (8.625 s) : 0, 8625016
Agent [candidate] (984.023 ms) : 0, 984023
Total [candidate] (8.604 s) : 0, 8604359
section appsec
Agent [baseline] (1.069 s) : 0, 1069342
Total [baseline] (8.687 s) : 0, 8686660
Agent [candidate] (1.07 s) : 0, 1070158
Total [candidate] (8.688 s) : 0, 8687534
section iast
Agent [baseline] (1.086 s) : 0, 1086330
Total [baseline] (9.112 s) : 0, 9111862
Agent [candidate] (1.089 s) : 0, 1088516
Total [candidate] (9.123 s) : 0, 9122555
section profiling
Agent [baseline] (1.155 s) : 0, 1155380
Total [baseline] (8.868 s) : 0, 8867745
Agent [candidate] (1.155 s) : 0, 1155042
Total [candidate] (8.861 s) : 0, 8860573
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 991.533 ms -
Agent appsec 1.069 s 77.809 ms (7.8%)
Agent iast 1.086 s 94.797 ms (9.6%)
Agent profiling 1.155 s 163.847 ms (16.5%)
Total tracing 8.625 s -
Total appsec 8.687 s 61.644 ms (0.7%)
Total iast 9.112 s 486.847 ms (5.6%)
Total profiling 8.868 s 242.729 ms (2.8%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 984.023 ms -
Agent appsec 1.07 s 86.135 ms (8.8%)
Agent iast 1.089 s 104.493 ms (10.6%)
Agent profiling 1.155 s 171.019 ms (17.4%)
Total tracing 8.604 s -
Total appsec 8.688 s 83.175 ms (1.0%)
Total iast 9.123 s 518.196 ms (6.0%)
Total profiling 8.861 s 256.214 ms (3.0%)
gantt
    title insecure-bank - break down per module: candidate=1.20.0-SNAPSHOT~5599c5a44e, baseline=1.20.0-SNAPSHOT~4663dd598c

    dateFormat X
    axisFormat %s
section tracing
BytebuddyAgent [baseline] (614.267 ms) : 0, 614267
BytebuddyAgent [candidate] (609.424 ms) : 0, 609424
GlobalTracer [baseline] (285.617 ms) : 0, 285617
GlobalTracer [candidate] (283.439 ms) : 0, 283439
AppSec [baseline] (50.405 ms) : 0, 50405
AppSec [candidate] (50.273 ms) : 0, 50273
Remote Config [baseline] (667.721 µs) : 0, 668
Remote Config [candidate] (654.136 µs) : 0, 654
Telemetry [baseline] (6.029 ms) : 0, 6029
Telemetry [candidate] (5.957 ms) : 0, 5957
section appsec
BytebuddyAgent [baseline] (610.125 ms) : 0, 610125
BytebuddyAgent [candidate] (610.338 ms) : 0, 610338
GlobalTracer [baseline] (283.498 ms) : 0, 283498
GlobalTracer [candidate] (283.618 ms) : 0, 283618
AppSec [baseline] (135.11 ms) : 0, 135110
AppSec [candidate] (135.485 ms) : 0, 135485
Remote Config [baseline] (722.113 µs) : 0, 722
Remote Config [candidate] (717.963 µs) : 0, 718
Telemetry [baseline] (5.697 ms) : 0, 5697
Telemetry [candidate] (5.705 ms) : 0, 5705
section iast
BytebuddyAgent [baseline] (715.246 ms) : 0, 715246
BytebuddyAgent [candidate] (716.641 ms) : 0, 716641
GlobalTracer [baseline] (269.953 ms) : 0, 269953
GlobalTracer [candidate] (270.384 ms) : 0, 270384
AppSec [baseline] (46.873 ms) : 0, 46873
AppSec [candidate] (47.104 ms) : 0, 47104
Remote Config [baseline] (546.658 µs) : 0, 547
Remote Config [candidate] (549.739 µs) : 0, 550
Telemetry [baseline] (5.734 ms) : 0, 5734
Telemetry [candidate] (5.744 ms) : 0, 5744
IAST [baseline] (13.759 ms) : 0, 13759
IAST [candidate] (13.887 ms) : 0, 13887
section profiling
BytebuddyAgent [baseline] (623.007 ms) : 0, 623007
BytebuddyAgent [candidate] (622.581 ms) : 0, 622581
GlobalTracer [baseline] (348.41 ms) : 0, 348410
GlobalTracer [candidate] (348.19 ms) : 0, 348190
AppSec [baseline] (49.28 ms) : 0, 49280
AppSec [candidate] (49.008 ms) : 0, 49008
Remote Config [baseline] (664.57 µs) : 0, 665
Remote Config [candidate] (653.168 µs) : 0, 653
Telemetry [baseline] (5.931 ms) : 0, 5931
Telemetry [candidate] (5.873 ms) : 0, 5873
ProfilingAgent [baseline] (75.163 ms) : 0, 75163
ProfilingAgent [candidate] (75.985 ms) : 0, 75985
Profiling [baseline] (75.186 ms) : 0, 75186
Profiling [candidate] (76.01 ms) : 0, 76010
Loading

Load

Parameters

Baseline Candidate
commit 1.20.0-SNAPSHOT~4663dd598c 1.20.0-SNAPSHOT~5599c5a44e
config baseline candidate
end_time 2023-08-18T13:47:58 2023-08-18T14:06:00
start_time 2023-08-18T13:47:40 2023-08-18T14:05:43
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
variant appsec appsec

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 24 cases.

Request duration reports for petclinic
gantt
    title petclinic - request duration [CI 0.99] : candidate=1.20.0-SNAPSHOT~5599c5a44e, baseline=1.20.0-SNAPSHOT~4663dd598c
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.33 ms) : 1311, 1348
.   : milestone, 1330,
appsec (1.659 ms) : 1635, 1683
.   : milestone, 1659,
iast (1.459 ms) : 1435, 1483
.   : milestone, 1459,
profiling (1.465 ms) : 1439, 1491
.   : milestone, 1465,
tracing (1.43 ms) : 1405, 1456
.   : milestone, 1430,
section candidate
no_agent (1.322 ms) : 1303, 1341
.   : milestone, 1322,
appsec (1.689 ms) : 1664, 1713
.   : milestone, 1689,
iast (1.442 ms) : 1418, 1467
.   : milestone, 1442,
profiling (1.474 ms) : 1448, 1500
.   : milestone, 1474,
tracing (1.436 ms) : 1412, 1460
.   : milestone, 1436,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.33 ms [1.311 ms, 1.348 ms] -
appsec 1.659 ms [1.635 ms, 1.683 ms] 329.433 µs (24.8%)
iast 1.459 ms [1.435 ms, 1.483 ms] 129.023 µs (9.7%)
profiling 1.465 ms [1.439 ms, 1.491 ms] 135.181 µs (10.2%)
tracing 1.43 ms [1.405 ms, 1.456 ms] 100.297 µs (7.5%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.322 ms [1.303 ms, 1.341 ms] -
appsec 1.689 ms [1.664 ms, 1.713 ms] 366.998 µs (27.8%)
iast 1.442 ms [1.418 ms, 1.467 ms] 120.244 µs (9.1%)
profiling 1.474 ms [1.448 ms, 1.5 ms] 152.283 µs (11.5%)
tracing 1.436 ms [1.412 ms, 1.46 ms] 114.31 µs (8.6%)
Request duration reports for insecure-bank
gantt
    title insecure-bank - request duration [CI 0.99] : candidate=1.20.0-SNAPSHOT~5599c5a44e, baseline=1.20.0-SNAPSHOT~4663dd598c
    dateFormat X
    axisFormat %s
section baseline
no_agent (351.533 µs) : 331, 372
.   : milestone, 352,
appsec (656.46 µs) : 636, 677
.   : milestone, 656,
iast (455.572 µs) : 435, 476
.   : milestone, 456,
iast_FULL (516.515 µs) : 496, 537
.   : milestone, 517,
iast_INACTIVE (428.113 µs) : 407, 449
.   : milestone, 428,
profiling (444.149 µs) : 423, 465
.   : milestone, 444,
tracing (430.72 µs) : 410, 452
.   : milestone, 431,
section candidate
no_agent (355.464 µs) : 336, 375
.   : milestone, 355,
appsec (654.682 µs) : 634, 675
.   : milestone, 655,
iast (451.633 µs) : 431, 472
.   : milestone, 452,
iast_FULL (514.295 µs) : 494, 535
.   : milestone, 514,
iast_INACTIVE (432.313 µs) : 411, 454
.   : milestone, 432,
profiling (436.768 µs) : 415, 458
.   : milestone, 437,
tracing (427.212 µs) : 406, 448
.   : milestone, 427,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 351.533 µs [331.254 µs, 371.813 µs] -
appsec 656.46 µs [636.119 µs, 676.801 µs] 304.927 µs (86.7%)
iast 455.572 µs [434.902 µs, 476.241 µs] 104.038 µs (29.6%)
iast_FULL 516.515 µs [495.988 µs, 537.043 µs] 164.982 µs (46.9%)
iast_INACTIVE 428.113 µs [407.252 µs, 448.973 µs] 76.579 µs (21.8%)
profiling 444.149 µs [423.188 µs, 465.111 µs] 92.616 µs (26.3%)
tracing 430.72 µs [409.897 µs, 451.544 µs] 79.187 µs (22.5%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 355.464 µs [335.527 µs, 375.4 µs] -
appsec 654.682 µs [634.352 µs, 675.012 µs] 299.218 µs (84.2%)
iast 451.633 µs [431.024 µs, 472.243 µs] 96.17 µs (27.1%)
iast_FULL 514.295 µs [493.563 µs, 535.027 µs] 158.831 µs (44.7%)
iast_INACTIVE 432.313 µs [410.955 µs, 453.672 µs] 76.85 µs (21.6%)
profiling 436.768 µs [415.377 µs, 458.158 µs] 81.304 µs (22.9%)
tracing 427.212 µs [406.219 µs, 448.205 µs] 71.748 µs (20.2%)

@mcculls mcculls changed the title [WIP] Avoid creating new ContinuingScope if the top scope is already keeping the span alive Avoid creating new ContinuingScope if the top scope is already keeping the span alive Aug 18, 2023
@mcculls mcculls removed the tag: do not merge Do not merge changes label Aug 18, 2023
@mcculls
mcculls marked this pull request as ready for review August 18, 2023 14:51
@mcculls
mcculls requested a review from a team as a code owner August 18, 2023 14:51
@mcculls
mcculls requested a review from bantonsson August 18, 2023 14:52
@mcculls
mcculls merged commit d99ffb8 into master Aug 18, 2023
@mcculls
mcculls deleted the mcculls/reduce-scope-allocations branch August 18, 2023 15:28
@github-actions github-actions Bot added this to the 1.20.0 milestone Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: performance Performance related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants