From c58e0086b556780d1925dec8ca9f132e9e19866c Mon Sep 17 00:00:00 2001 From: r1viollet Date: Wed, 9 Jul 2025 16:53:07 +0200 Subject: [PATCH] Stresstest fix - Add limits to the graph mutation stress test --- .../stresstest/scenarios/counters/GraphMutation.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ddprof-stresstest/src/jmh/java/com/datadoghq/profiler/stresstest/scenarios/counters/GraphMutation.java b/ddprof-stresstest/src/jmh/java/com/datadoghq/profiler/stresstest/scenarios/counters/GraphMutation.java index 58a2e6cd..7a82d4d1 100644 --- a/ddprof-stresstest/src/jmh/java/com/datadoghq/profiler/stresstest/scenarios/counters/GraphMutation.java +++ b/ddprof-stresstest/src/jmh/java/com/datadoghq/profiler/stresstest/scenarios/counters/GraphMutation.java @@ -3,17 +3,24 @@ import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Threads; -import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicLong; public class GraphMutation { public static class GraphNode { - private final Queue nodes = new ConcurrentLinkedQueue<>(); + private volatile ConcurrentLinkedQueue nodes = new ConcurrentLinkedQueue<>(); + private final AtomicLong linkCount = new AtomicLong(0); public void link(GraphNode node) { nodes.add(node); + + // Switch to new data structure every 100,000 operations + // Other threads can finish with the old one + if (linkCount.incrementAndGet() % 100000 == 0) { + nodes = new ConcurrentLinkedQueue<>(); + } } }