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 58a2e6cd4..7a82d4d1f 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<>(); + } } }