File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
ddprof-stresstest/src/jmh/java/com/datadoghq/profiler/stresstest/scenarios/counters Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 33import org .openjdk .jmh .annotations .Benchmark ;
44import org .openjdk .jmh .annotations .Threads ;
55
6- import java .util .Queue ;
7- import java .util .concurrent .ConcurrentLinkedQueue ;
86import java .util .concurrent .ThreadLocalRandom ;
7+ import java .util .concurrent .atomic .AtomicReferenceArray ;
98
109public class GraphMutation {
1110
1211 public static class GraphNode {
13- private final Queue <GraphNode > nodes = new ConcurrentLinkedQueue <>();
12+ // Use a fixed-size array instead of unbounded queue
13+ // This naturally bounds memory while still allowing realistic stress testing
14+ private static final int MAX_LINKS = 10000 ;
15+ private final AtomicReferenceArray <GraphNode > links = new AtomicReferenceArray <>(MAX_LINKS );
16+ private volatile int linkIndex = 0 ;
1417
1518 public void link (GraphNode node ) {
16- nodes .add (node );
19+ // Simple round-robin replacement - no expensive size checks or polling
20+ int index = (linkIndex ++) % MAX_LINKS ;
21+ links .set (index , node );
22+ }
23+
24+ // Optional: method to access links if needed for verification
25+ public GraphNode getLink (int index ) {
26+ return links .get (index % MAX_LINKS );
1727 }
1828 }
1929
You can’t perform that action at this time.
0 commit comments