Skip to content

Don't poll discovery service if we've received an update from the agent recently#7979

Merged
andrewlock merged 6 commits intomasterfrom
andrew/service-discovery-polling
Jan 13, 2026
Merged

Don't poll discovery service if we've received an update from the agent recently#7979
andrewlock merged 6 commits intomasterfrom
andrew/service-discovery-polling

Conversation

@andrewlock
Copy link
Member

Summary of changes

Don't poll discovery service if we're received an update from the agent recently

Reason for change

The agent sends a sha256 hash of the /info endpoint data in every response. We can use that to track whether the /info value has changed, and if it hasn't, we can skip polling the endpoint needlessly.

This obviously removes the overhead of polling the endpoint, but it's not entirely clear the impact this will have on performance, as we're doing "extra" work by materializing the header and calling the discovery service, everytime we send a trace.

Implementation details

  • When polling the /info data, take a SHA256 of the data, and store it as a hex string
  • After sending a trace, grab the state-config-hash header and pass it to the DiscoveryService
  • When the DiscoveryService is next due to poll (every 30s) check if the existing hash matches the most recent value from the header (and that it was received within the last 30s). If so, skip the current poll.

Test coverage

Added unit tests for all of the components

Other details

https://datadoghq.atlassian.net/browse/LANGPLAT-815

Couple of points of interest:

  • Using CryptoStream makes calculating the hash low allocation, but it assumes we're receiving the data as UTF-8 etc (which we are, but you know, we don't currently verify that)
  • It's kind of tough to measure the perf impact of this. We're assuming that the overhead of materialising the string (if it's not already, it will be in many if not all TFMs) and invoking the action on every send to the agent will be lower than polling the agent once every 30s. But proving that will be tricky

@andrewlock andrewlock added the type:performance Performance, speed, latency, resource usage (CPU, memory) label Dec 19, 2025
@andrewlock andrewlock requested review from a team as code owners December 19, 2025 14:54
@andrewlock andrewlock force-pushed the andrew/service-discovery-polling branch from 7f41b60 to 80d155a Compare December 19, 2025 14:55
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-datadog-prod-us1

This comment has been minimized.

@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Dec 19, 2025

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7979) and master.

✅ No regressions detected - check the details below

Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration68.63 ± (68.61 - 68.88) ms68.62 ± (68.60 - 68.81) ms-0.0%
.NET Framework 4.8 - Bailout
duration72.39 ± (72.29 - 72.52) ms72.23 ± (72.17 - 72.43) ms-0.2%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1010.89 ± (1014.65 - 1022.32) ms1011.35 ± (1018.16 - 1029.13) ms+0.0%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms21.97 ± (21.94 - 22.00) ms21.97 ± (21.94 - 22.01) ms+0.0%✅⬆️
process.time_to_main_ms79.57 ± (79.41 - 79.72) ms79.05 ± (78.89 - 79.20) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.93 ± (10.93 - 10.93) MB10.92 ± (10.91 - 10.92) MB-0.1%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.88 ± (21.86 - 21.91) ms21.89 ± (21.86 - 21.91) ms+0.0%✅⬆️
process.time_to_main_ms80.68 ± (80.55 - 80.81) ms80.09 ± (80.00 - 80.18) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.97 ± (10.97 - 10.98) MB10.95 ± (10.94 - 10.95) MB-0.2%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms245.30 ± (241.13 - 249.47) ms243.38 ± (240.18 - 246.59) ms-0.8%
process.time_to_main_ms474.30 ± (473.65 - 474.94) ms466.49 ± (465.96 - 467.02) ms-1.6%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.24 ± (48.22 - 48.27) MB48.29 ± (48.26 - 48.32) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.0%
.NET 6 - Baseline
process.internal_duration_ms20.93 ± (20.89 - 20.96) ms20.82 ± (20.80 - 20.85) ms-0.5%
process.time_to_main_ms68.96 ± (68.84 - 69.08) ms68.46 ± (68.35 - 68.56) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.62 - 10.62) MB10.65 ± (10.64 - 10.65) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.97 ± (20.90 - 21.04) ms20.60 ± (20.58 - 20.62) ms-1.8%
process.time_to_main_ms70.62 ± (70.26 - 70.97) ms69.09 ± (69.04 - 69.15) ms-2.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.69 ± (10.69 - 10.69) MB10.74 ± (10.74 - 10.75) MB+0.5%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms242.20 ± (239.34 - 245.05) ms244.34 ± (241.83 - 246.84) ms+0.9%✅⬆️
process.time_to_main_ms445.58 ± (445.03 - 446.13) ms444.47 ± (444.05 - 444.89) ms-0.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.79 ± (48.75 - 48.82) MB49.13 ± (49.10 - 49.16) MB+0.7%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 8 - Baseline
process.internal_duration_ms18.99 ± (18.96 - 19.02) ms18.77 ± (18.74 - 18.80) ms-1.2%
process.time_to_main_ms68.19 ± (68.06 - 68.33) ms67.20 ± (67.10 - 67.30) ms-1.5%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.67 ± (7.67 - 7.68) MB7.67 ± (7.66 - 7.67) MB-0.1%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.04 ± (19.02 - 19.07) ms18.90 ± (18.87 - 18.92) ms-0.8%
process.time_to_main_ms70.01 ± (69.89 - 70.13) ms68.65 ± (68.57 - 68.72) ms-1.9%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.74 ± (7.73 - 7.75) MB7.73 ± (7.72 - 7.74) MB-0.1%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms180.36 ± (179.60 - 181.12) ms178.89 ± (177.87 - 179.90) ms-0.8%
process.time_to_main_ms428.44 ± (427.92 - 428.96) ms427.53 ± (426.95 - 428.10) ms-0.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.33 ± (36.30 - 36.35) MB36.47 ± (36.44 - 36.50) MB+0.4%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (26 - 27)-0.3%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration191.92 ± (191.74 - 192.54) ms191.23 ± (191.45 - 192.32) ms-0.4%
.NET Framework 4.8 - Bailout
duration195.26 ± (195.00 - 195.59) ms195.45 ± (195.26 - 195.81) ms+0.1%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1111.92 ± (1117.97 - 1126.89) ms1108.40 ± (1111.00 - 1119.52) ms-0.3%
.NET Core 3.1 - Baseline
process.internal_duration_ms186.22 ± (185.87 - 186.57) ms186.95 ± (186.60 - 187.30) ms+0.4%✅⬆️
process.time_to_main_ms79.85 ± (79.65 - 80.05) ms80.16 ± (79.95 - 80.37) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.16 - 16.21) MB16.16 ± (16.14 - 16.19) MB-0.1%
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)-0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms186.55 ± (186.22 - 186.87) ms186.50 ± (186.18 - 186.81) ms-0.0%
process.time_to_main_ms81.17 ± (81.04 - 81.29) ms81.39 ± (81.25 - 81.54) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.19 ± (16.16 - 16.23) MB16.16 ± (16.13 - 16.19) MB-0.2%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)-0.1%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms423.58 ± (420.33 - 426.84) ms432.83 ± (430.33 - 435.33) ms+2.2%✅⬆️
process.time_to_main_ms473.14 ± (472.36 - 473.92) ms468.74 ± (468.18 - 469.31) ms-0.9%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.72 ± (58.60 - 58.84) MB58.84 ± (58.73 - 58.96) MB+0.2%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 30)29 ± (29 - 29)-0.2%
.NET 6 - Baseline
process.internal_duration_ms190.94 ± (190.63 - 191.25) ms191.20 ± (190.88 - 191.52) ms+0.1%✅⬆️
process.time_to_main_ms69.18 ± (69.02 - 69.34) ms69.36 ± (69.21 - 69.52) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.25 ± (16.13 - 16.36) MB15.91 ± (15.80 - 16.02) MB-2.1%
runtime.dotnet.threads.count19 ± (19 - 19)18 ± (18 - 18)-3.9%
.NET 6 - Bailout
process.internal_duration_ms190.02 ± (189.71 - 190.34) ms190.50 ± (190.18 - 190.81) ms+0.2%✅⬆️
process.time_to_main_ms70.05 ± (69.94 - 70.15) ms70.46 ± (70.35 - 70.57) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed15.81 ± (15.65 - 15.98) MB15.88 ± (15.72 - 16.05) MB+0.4%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.2%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms451.87 ± (449.52 - 454.21) ms451.59 ± (449.69 - 453.48) ms-0.1%
process.time_to_main_ms445.44 ± (444.88 - 445.99) ms445.59 ± (445.14 - 446.03) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.40 ± (58.30 - 58.49) MB58.66 ± (58.54 - 58.78) MB+0.5%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms188.64 ± (188.31 - 188.97) ms189.42 ± (189.05 - 189.80) ms+0.4%✅⬆️
process.time_to_main_ms68.58 ± (68.40 - 68.77) ms69.00 ± (68.82 - 69.19) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.76 ± (11.73 - 11.79) MB11.74 ± (11.72 - 11.77) MB-0.2%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.1%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms188.40 ± (188.17 - 188.63) ms189.11 ± (188.74 - 189.48) ms+0.4%✅⬆️
process.time_to_main_ms69.52 ± (69.43 - 69.61) ms70.08 ± (69.97 - 70.20) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.61 ± (11.50 - 11.72) MB11.82 ± (11.75 - 11.88) MB+1.8%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 19)19 ± (19 - 19)+3.5%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms361.95 ± (360.40 - 363.49) ms366.45 ± (365.15 - 367.76) ms+1.2%✅⬆️
process.time_to_main_ms427.07 ± (426.48 - 427.67) ms430.92 ± (430.33 - 431.52) ms+0.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed47.99 ± (47.95 - 48.02) MB48.15 ± (48.11 - 48.19) MB+0.3%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.2%✅⬆️
Comparison explanation

Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (69ms)  : 67, 70
    master - mean (69ms)  : 67, 70

    section Bailout
    This PR (7979) - mean (72ms)  : 71, 74
    master - mean (72ms)  : 71, 73

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (1,024ms)  : 943, 1104
    master - mean (1,018ms)  : 964, 1073

Loading
FakeDbCommand (.NET Core 3.1)
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (106ms)  : 103, 110
    master - mean (107ms)  : 104, 109

    section Bailout
    This PR (7979) - mean (107ms)  : 106, 108
    master - mean (108ms)  : 106, 110

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (739ms)  : 691, 787
    master - mean (746ms)  : 672, 820

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (94ms)  : 92, 96
    master - mean (95ms)  : 92, 98

    section Bailout
    This PR (7979) - mean (94ms)  : 93, 95
    master - mean (97ms)  : 89, 104

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (716ms)  : 678, 753
    master - mean (714ms)  : 665, 762

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (92ms)  : 90, 95
    master - mean (94ms)  : 90, 97

    section Bailout
    This PR (7979) - mean (94ms)  : 92, 95
    master - mean (95ms)  : 93, 97

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (634ms)  : 619, 650
    master - mean (638ms)  : 615, 662

Loading
HttpMessageHandler (.NET Framework 4.8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (192ms)  : 187, 196
    master - mean (192ms)  : 188, 196

    section Bailout
    This PR (7979) - mean (196ms)  : 193, 198
    master - mean (195ms)  : 192, 198

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (1,115ms)  : 1053, 1177
    master - mean (1,122ms)  : 1059, 1186

Loading
HttpMessageHandler (.NET Core 3.1)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (275ms)  : 270, 280
    master - mean (275ms)  : 269, 280

    section Bailout
    This PR (7979) - mean (276ms)  : 271, 281
    master - mean (276ms)  : 272, 280

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (931ms)  : 895, 967
    master - mean (925ms)  : 873, 978

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (268ms)  : 262, 275
    master - mean (268ms)  : 264, 273

    section Bailout
    This PR (7979) - mean (269ms)  : 265, 273
    master - mean (268ms)  : 264, 272

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (924ms)  : 886, 963
    master - mean (927ms)  : 890, 965

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7979) - mean (268ms)  : 263, 273
    master - mean (267ms)  : 262, 272

    section Bailout
    This PR (7979) - mean (268ms)  : 264, 273
    master - mean (267ms)  : 264, 271

    section CallTarget+Inlining+NGEN
    This PR (7979) - mean (830ms)  : 812, 847
    master - mean (819ms)  : 797, 841

Loading

@pr-commenter
Copy link

pr-commenter bot commented Dec 19, 2025

Benchmarks

Benchmark execution time: 2026-01-12 16:20:55

Comparing candidate commit f562bd6 in PR branch andrew/service-discovery-polling with baseline commit 7d0005d in branch master.

Found 5 performance improvements and 9 performance regressions! Performance is the same for 159 metrics, 13 unstable metrics.

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1

  • 🟩 execution_time [-26.109ms; -19.784ms] or [-11.971%; -9.071%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0

  • 🟥 execution_time [+14.320ms; +17.716ms] or [+7.272%; +8.997%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1

  • 🟥 execution_time [+15.877ms; +21.353ms] or [+8.021%; +10.786%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1

  • 🟩 execution_time [-16.817ms; -15.801ms] or [-8.401%; -7.893%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1

  • 🟥 execution_time [+17.689µs; +45.418µs] or [+5.455%; +14.006%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟩 execution_time [-37.156ms; -32.164ms] or [-15.332%; -13.272%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟩 throughput [+93.302op/s; +198.899op/s] or [+7.179%; +15.304%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net6.0

  • 🟥 execution_time [+136.174µs; +182.372µs] or [+7.040%; +9.428%]
  • 🟥 throughput [-44.065op/s; -34.204op/s] or [-8.524%; -6.616%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟥 throughput [-305.117op/s; -108.964op/s] or [-14.565%; -5.202%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • 🟩 throughput [+1760.863op/s; +3783.961op/s] or [+8.549%; +18.371%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+41.878ms; +43.503ms] or [+26.515%; +27.544%]

scenario:Benchmarks.Trace.NLogBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+10.329ms; +14.200ms] or [+5.199%; +7.147%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • 🟥 execution_time [+18.110ms; +21.728ms] or [+9.171%; +11.004%]

@andrewlock andrewlock force-pushed the andrew/service-discovery-polling branch 3 times, most recently from 46bf894 to e985c05 Compare December 23, 2025 10:38
}

[TestingAndPrivateOnly]
internal bool RequireRefresh(string? currentHash, DateTimeOffset utcNow)
Copy link
Collaborator

@NachoEchevarria NachoEchevarria Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be a race condition here?
Thread A reads _agentConfigStateHash
Thread B calls SetCurrentConfigStateHash() and updates hash and time
Thread A reads _agentConfigStateHashUnixTime and gets a fresh timestamp, return false
Not critical though, it would be rare and the consecuences are not severe. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be a race condition here?

Yup, absolutely, there could. When I first wrote this, I worked around that by creating a record State(string Hash, DateTimeOffset utcNow) and then atomically switching that. The problem is that SetCurrentConfigStateHash() is going to be called a lot, so it would result in either a more complex "atomically read, compare, conditionally recreate , atomically write" comparison, or if we just always write (like we're doing currently) then we end up allocating every time.

My conclusion was pretty much the same as yours, it should be rare, and not severe (we will pick it up next time), and given this is primarily meant to be a perf improvement, I think it's worth it 🙂

Copy link
Collaborator

@NachoEchevarria NachoEchevarria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Collaborator

@bouwkast bouwkast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lucaspimentel lucaspimentel changed the title Don't poll discovery service if we're received an update from the agent recently Don't poll discovery service if we've received an update from the agent recently Jan 9, 2026
@andrewlock andrewlock force-pushed the andrew/service-discovery-polling branch from e985c05 to c50e32e Compare January 12, 2026 13:46
@andrewlock andrewlock force-pushed the andrew/service-discovery-polling branch from c50e32e to f562bd6 Compare January 12, 2026 15:39
@andrewlock andrewlock enabled auto-merge (squash) January 12, 2026 19:18
@andrewlock andrewlock merged commit e764036 into master Jan 13, 2026
154 checks passed
@andrewlock andrewlock deleted the andrew/service-discovery-polling branch January 13, 2026 12:02
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:performance Performance, speed, latency, resource usage (CPU, memory)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants