Skip to content

Commit fda18b4

Browse files
author
rogersimmons
committed
Optional busywait for jitter test
1 parent ad5e622 commit fda18b4

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,22 @@ public class MicroJitterSampler {
7979
20 * 1000 * 1000, 50 * 1000 * 1000, 100 * 1000 * 1000
8080
};
8181
private static final double UTIL = Double.parseDouble(System.getProperty("util", "50"));
82+
private static final boolean BUSYWAIT = Boolean.parseBoolean(System.getProperty("busywait", "false"));
83+
8284
// static final int CPU = Integer.getInteger("cpu", 0);
8385
private final int[] count = new int[DELAY.length];
8486
private long totalTime = 0;
8587

88+
private static void pause() throws InterruptedException
89+
{
90+
if(BUSYWAIT) {
91+
long now = System.nanoTime();
92+
while(System.nanoTime() - now < 1_000_000);
93+
} else {
94+
Thread.sleep(1);
95+
}
96+
97+
}
8698
public static void main(String... ignored) throws InterruptedException {
8799
// AffinityLock al = AffinityLock.acquireLock();
88100

@@ -98,7 +110,7 @@ public static void main(String... ignored) throws InterruptedException {
98110
for (int i = 0; i < 30 * 1000; i += 2) {
99111
microJitterSampler.sample(sampleLength);
100112
//noinspection BusyWait
101-
Thread.sleep(1);
113+
pause();
102114
}
103115
}
104116

0 commit comments

Comments
 (0)