Improve VirtualThread context tracking instrumentation#11009
Improve VirtualThread context tracking instrumentation#11009gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits intomasterfrom
Conversation
…en VirtualThread and Runnable
Replaces the `ConcurrentState` approach (which activated/closed individual scopes) with `VirtualThreadState` that swaps the entire scope stack via `Context#swap()`. This correctly handles child spans created during virtual thread execution and avoids out-of-order scope closing. The new approach mirrors the ZIO FiberContext and Kotlin coroutines instrumentation patterns.
ea327b5 to
d0e39d9
Compare
Replaces the `ConcurrentState` approach (which activated/closed individual scopes) with `VirtualThreadState` that swaps the entire scope stack via `Context#swap()`. This correctly handles child spans created during virtual thread execution and avoids out-of-order scope closing. The new approach mirrors the ZIO FiberContext and Kotlin coroutines instrumentation patterns.
2788193 to
45d06be
Compare
BenchmarksStartupParameters
See matching parameters
SummaryFound 1 performance improvements and 0 performance regressions! Performance is the same for 59 metrics, 11 unstable metrics.
Startup time reports for petclinicgantt
title petclinic - global startup overhead: candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.058 s) : 0, 1057952
Total [baseline] (11.153 s) : 0, 11152550
Agent [candidate] (1.065 s) : 0, 1065247
Total [candidate] (11.066 s) : 0, 11066194
section appsec
Agent [baseline] (1.257 s) : 0, 1256514
Total [baseline] (11.155 s) : 0, 11154973
Agent [candidate] (1.251 s) : 0, 1251422
Total [candidate] (11.161 s) : 0, 11161465
section iast
Agent [baseline] (1.235 s) : 0, 1234778
Total [baseline] (11.353 s) : 0, 11352614
Agent [candidate] (1.222 s) : 0, 1221943
Total [candidate] (11.403 s) : 0, 11403105
section profiling
Agent [baseline] (1.192 s) : 0, 1191753
Total [baseline] (11.061 s) : 0, 11060796
Agent [candidate] (1.191 s) : 0, 1191419
Total [candidate] (11.251 s) : 0, 11250924
gantt
title petclinic - break down per module: candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.201 ms) : 0, 1201
crashtracking [candidate] (1.236 ms) : 0, 1236
BytebuddyAgent [baseline] (634.036 ms) : 0, 634036
BytebuddyAgent [candidate] (637.372 ms) : 0, 637372
AgentMeter [baseline] (29.55 ms) : 0, 29550
AgentMeter [candidate] (29.643 ms) : 0, 29643
GlobalTracer [baseline] (249.299 ms) : 0, 249299
GlobalTracer [candidate] (250.895 ms) : 0, 250895
AppSec [baseline] (32.179 ms) : 0, 32179
AppSec [candidate] (32.319 ms) : 0, 32319
Debugger [baseline] (60.179 ms) : 0, 60179
Debugger [candidate] (60.645 ms) : 0, 60645
Remote Config [baseline] (628.654 µs) : 0, 629
Remote Config [candidate] (596.195 µs) : 0, 596
Telemetry [baseline] (8.117 ms) : 0, 8117
Telemetry [candidate] (8.165 ms) : 0, 8165
Flare Poller [baseline] (6.636 ms) : 0, 6636
Flare Poller [candidate] (8.217 ms) : 0, 8217
section appsec
crashtracking [baseline] (1.212 ms) : 0, 1212
crashtracking [candidate] (1.208 ms) : 0, 1208
BytebuddyAgent [baseline] (668.746 ms) : 0, 668746
BytebuddyAgent [candidate] (666.145 ms) : 0, 666145
AgentMeter [baseline] (12.22 ms) : 0, 12220
AgentMeter [candidate] (12.16 ms) : 0, 12160
GlobalTracer [baseline] (249.627 ms) : 0, 249627
GlobalTracer [candidate] (248.423 ms) : 0, 248423
IAST [baseline] (24.575 ms) : 0, 24575
IAST [candidate] (24.481 ms) : 0, 24481
AppSec [baseline] (184.131 ms) : 0, 184131
AppSec [candidate] (183.646 ms) : 0, 183646
Debugger [baseline] (66.272 ms) : 0, 66272
Debugger [candidate] (66.299 ms) : 0, 66299
Remote Config [baseline] (612.072 µs) : 0, 612
Remote Config [candidate] (603.135 µs) : 0, 603
Telemetry [baseline] (8.807 ms) : 0, 8807
Telemetry [candidate] (8.553 ms) : 0, 8553
Flare Poller [baseline] (3.631 ms) : 0, 3631
Flare Poller [candidate] (3.528 ms) : 0, 3528
section iast
crashtracking [baseline] (1.195 ms) : 0, 1195
crashtracking [candidate] (1.182 ms) : 0, 1182
BytebuddyAgent [baseline] (807.734 ms) : 0, 807734
BytebuddyAgent [candidate] (799.332 ms) : 0, 799332
AgentMeter [baseline] (11.454 ms) : 0, 11454
AgentMeter [candidate] (11.369 ms) : 0, 11369
GlobalTracer [baseline] (241.238 ms) : 0, 241238
GlobalTracer [candidate] (238.334 ms) : 0, 238334
IAST [baseline] (26.225 ms) : 0, 26225
IAST [candidate] (25.884 ms) : 0, 25884
AppSec [baseline] (32.02 ms) : 0, 32020
AppSec [candidate] (30.372 ms) : 0, 30372
Debugger [baseline] (59.128 ms) : 0, 59128
Debugger [candidate] (61.806 ms) : 0, 61806
Remote Config [baseline] (530.134 µs) : 0, 530
Remote Config [candidate] (523.528 µs) : 0, 524
Telemetry [baseline] (14.466 ms) : 0, 14466
Telemetry [candidate] (12.636 ms) : 0, 12636
Flare Poller [baseline] (4.165 ms) : 0, 4165
Flare Poller [candidate] (4.183 ms) : 0, 4183
section profiling
crashtracking [baseline] (1.197 ms) : 0, 1197
crashtracking [candidate] (1.177 ms) : 0, 1177
BytebuddyAgent [baseline] (696.292 ms) : 0, 696292
BytebuddyAgent [candidate] (694.587 ms) : 0, 694587
AgentMeter [baseline] (9.215 ms) : 0, 9215
AgentMeter [candidate] (9.114 ms) : 0, 9114
GlobalTracer [baseline] (208.735 ms) : 0, 208735
GlobalTracer [candidate] (207.875 ms) : 0, 207875
AppSec [baseline] (32.9 ms) : 0, 32900
AppSec [candidate] (32.955 ms) : 0, 32955
Debugger [baseline] (65.855 ms) : 0, 65855
Debugger [candidate] (66.416 ms) : 0, 66416
Remote Config [baseline] (566.44 µs) : 0, 566
Remote Config [candidate] (576.655 µs) : 0, 577
Telemetry [baseline] (7.85 ms) : 0, 7850
Telemetry [candidate] (7.969 ms) : 0, 7969
Flare Poller [baseline] (3.597 ms) : 0, 3597
Flare Poller [candidate] (3.674 ms) : 0, 3674
ProfilingAgent [baseline] (93.636 ms) : 0, 93636
ProfilingAgent [candidate] (95.727 ms) : 0, 95727
Profiling [baseline] (94.201 ms) : 0, 94201
Profiling [candidate] (96.298 ms) : 0, 96298
Startup time reports for insecure-bankgantt
title insecure-bank - global startup overhead: candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.082 s) : 0, 1081896
Total [baseline] (8.987 s) : 0, 8986664
Agent [candidate] (1.05 s) : 0, 1049928
Total [candidate] (8.852 s) : 0, 8851585
section iast
Agent [baseline] (1.231 s) : 0, 1230866
Total [baseline] (9.624 s) : 0, 9623521
Agent [candidate] (1.232 s) : 0, 1232385
Total [candidate] (9.574 s) : 0, 9573566
gantt
title insecure-bank - break down per module: candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.247 ms) : 0, 1247
crashtracking [candidate] (1.179 ms) : 0, 1179
BytebuddyAgent [baseline] (649.781 ms) : 0, 649781
BytebuddyAgent [candidate] (630.7 ms) : 0, 630700
AgentMeter [baseline] (30.342 ms) : 0, 30342
AgentMeter [candidate] (29.242 ms) : 0, 29242
GlobalTracer [baseline] (254.782 ms) : 0, 254782
GlobalTracer [candidate] (248.192 ms) : 0, 248192
AppSec [baseline] (33.113 ms) : 0, 33113
AppSec [candidate] (31.887 ms) : 0, 31887
Debugger [baseline] (61.111 ms) : 0, 61111
Debugger [candidate] (59.142 ms) : 0, 59142
Remote Config [baseline] (614.076 µs) : 0, 614
Remote Config [candidate] (590.792 µs) : 0, 591
Telemetry [baseline] (8.376 ms) : 0, 8376
Telemetry [candidate] (7.988 ms) : 0, 7988
Flare Poller [baseline] (5.993 ms) : 0, 5993
Flare Poller [candidate] (5.073 ms) : 0, 5073
section iast
crashtracking [baseline] (1.202 ms) : 0, 1202
crashtracking [candidate] (1.191 ms) : 0, 1191
BytebuddyAgent [baseline] (805.728 ms) : 0, 805728
BytebuddyAgent [candidate] (805.318 ms) : 0, 805318
AgentMeter [baseline] (11.396 ms) : 0, 11396
AgentMeter [candidate] (11.578 ms) : 0, 11578
GlobalTracer [baseline] (240.742 ms) : 0, 240742
GlobalTracer [candidate] (241.292 ms) : 0, 241292
IAST [baseline] (26.126 ms) : 0, 26126
IAST [candidate] (26.301 ms) : 0, 26301
AppSec [baseline] (32.063 ms) : 0, 32063
AppSec [candidate] (29.967 ms) : 0, 29967
Debugger [baseline] (57.898 ms) : 0, 57898
Debugger [candidate] (61.633 ms) : 0, 61633
Remote Config [baseline] (528.712 µs) : 0, 529
Remote Config [candidate] (534.735 µs) : 0, 535
Telemetry [baseline] (14.77 ms) : 0, 14770
Telemetry [candidate] (13.634 ms) : 0, 13634
Flare Poller [baseline] (3.947 ms) : 0, 3947
Flare Poller [candidate] (4.761 ms) : 0, 4761
LoadParameters
See matching parameters
SummaryFound 3 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 18 unstable metrics.
Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section baseline
no_agent (1.242 ms) : 1230, 1255
. : milestone, 1242,
iast (3.336 ms) : 3288, 3384
. : milestone, 3336,
iast_FULL (6.018 ms) : 5959, 6078
. : milestone, 6018,
iast_GLOBAL (3.78 ms) : 3715, 3845
. : milestone, 3780,
profiling (2.335 ms) : 2312, 2358
. : milestone, 2335,
tracing (1.896 ms) : 1880, 1912
. : milestone, 1896,
section candidate
no_agent (1.244 ms) : 1232, 1256
. : milestone, 1244,
iast (3.265 ms) : 3219, 3311
. : milestone, 3265,
iast_FULL (5.984 ms) : 5923, 6045
. : milestone, 5984,
iast_GLOBAL (3.682 ms) : 3618, 3747
. : milestone, 3682,
profiling (2.281 ms) : 2259, 2304
. : milestone, 2281,
tracing (1.86 ms) : 1844, 1875
. : milestone, 1860,
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section baseline
no_agent (18.604 ms) : 18412, 18795
. : milestone, 18604,
appsec (18.864 ms) : 18676, 19052
. : milestone, 18864,
code_origins (18.066 ms) : 17884, 18248
. : milestone, 18066,
iast (19.229 ms) : 19030, 19428
. : milestone, 19229,
profiling (18.747 ms) : 18559, 18934
. : milestone, 18747,
tracing (18.581 ms) : 18394, 18769
. : milestone, 18581,
section candidate
no_agent (19.163 ms) : 18968, 19358
. : milestone, 19163,
appsec (18.798 ms) : 18607, 18988
. : milestone, 18798,
code_origins (17.962 ms) : 17785, 18138
. : milestone, 17962,
iast (18.092 ms) : 17910, 18275
. : milestone, 18092,
profiling (18.854 ms) : 18661, 19047
. : milestone, 18854,
tracing (18.026 ms) : 17846, 18206
. : milestone, 18026,
DacapoParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 11 metrics, 1 unstable metrics. Execution time for tomcatgantt
title tomcat - execution time [CI 0.99] : candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section baseline
no_agent (1.483 ms) : 1471, 1494
. : milestone, 1483,
appsec (3.82 ms) : 3598, 4043
. : milestone, 3820,
iast (2.273 ms) : 2204, 2342
. : milestone, 2273,
iast_GLOBAL (2.312 ms) : 2242, 2381
. : milestone, 2312,
profiling (2.111 ms) : 2055, 2167
. : milestone, 2111,
tracing (2.079 ms) : 2025, 2133
. : milestone, 2079,
section candidate
no_agent (1.486 ms) : 1474, 1497
. : milestone, 1486,
appsec (3.834 ms) : 3613, 4056
. : milestone, 3834,
iast (2.268 ms) : 2199, 2338
. : milestone, 2268,
iast_GLOBAL (2.317 ms) : 2247, 2387
. : milestone, 2317,
profiling (2.095 ms) : 2040, 2150
. : milestone, 2095,
tracing (2.077 ms) : 2023, 2130
. : milestone, 2077,
Execution time for biojavagantt
title biojava - execution time [CI 0.99] : candidate=1.61.0-SNAPSHOT~45d06beb1c, baseline=1.61.0-SNAPSHOT~e16815c31c
dateFormat X
axisFormat %s
section baseline
no_agent (15.157 s) : 15157000, 15157000
. : milestone, 15157000,
appsec (14.803 s) : 14803000, 14803000
. : milestone, 14803000,
iast (19.462 s) : 19462000, 19462000
. : milestone, 19462000,
iast_GLOBAL (17.766 s) : 17766000, 17766000
. : milestone, 17766000,
profiling (14.918 s) : 14918000, 14918000
. : milestone, 14918000,
tracing (14.743 s) : 14743000, 14743000
. : milestone, 14743000,
section candidate
no_agent (15.555 s) : 15555000, 15555000
. : milestone, 15555000,
appsec (14.851 s) : 14851000, 14851000
. : milestone, 14851000,
iast (18.334 s) : 18334000, 18334000
. : milestone, 18334000,
iast_GLOBAL (17.435 s) : 17435000, 17435000
. : milestone, 17435000,
profiling (14.884 s) : 14884000, 14884000
. : milestone, 14884000,
tracing (14.738 s) : 14738000, 14738000
. : milestone, 14738000,
|
|
|
||
| /** Called on mount: swaps the virtual thread's context into the carrier thread. */ | ||
| public void onMount() { | ||
| this.previousContext = this.context.swap(); |
There was a problem hiding this comment.
Nice, that's the kind of API that I was imagining
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What Does This Do
This PR addresses the following issues with
VirtualThreadinstrumentation:VirtualThreadas aRunnablewhen virtual thread instrumentation is enabledafterDone()andafterDone(boolean)leading to duplicate clearing workState/ConcurrentStateAPI instead of using the new Context swap API. This lead to ouf of order scope closing in addition to increase pressure on health metrics.Motivation
I did not check at bytecode level the changes from the original PRs and that was wrong. That introduces regression and keep pushing in the wrong direction. This is a basically a redo of the instrumentation using context swap and continuation.
Additional Notes
This PR also mirrors the context testing capability from the JUnit instrumentation tests.
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]
Note: Once your PR is ready to merge, add it to the merge queue by commenting
/merge./merge -ccancels the queue request./merge -f --reason "reason"skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.