Make affinity on EchoServerMain configurable
package net.openhft.performance.tests.vanilla.tcp;
import net.openhft.affinity.Affinity;
+import net.openhft.affinity.AffinityLock;
import net.openhft.chronicle.network.tcp.ChronicleServerSocketChannel;
import net.openhft.chronicle.network.tcp.ChronicleServerSocketFactory;
import net.openhft.chronicle.network.tcp.ChronicleSocketChannel;
@@ -34,6 +35,8 @@ import java.util.concurrent.atomic.AtomicReference;
* @author peter.lawrey
*/
public class EchoServerMain {
+ private static final String CPU = System.getProperty("cpu", "any");
+
public static void main(@NotNull String... args) throws IOException {
int port = args.length < 1 ? EchoClientMain.PORT : Integer.parseInt(args[0]);
ChronicleServerSocketChannel ssc = ChronicleServerSocketFactory.open("localhost:" + port);
@@ -43,7 +46,7 @@ public class EchoServerMain {
@NotNull AtomicReference<ChronicleSocketChannel> nextSocket = new AtomicReference<>();
new Thread(() -> {
- Affinity.acquireCore();
+ try (final AffinityLock lock = AffinityLock.acquireLock(CPU)) {
System.out.println("Running on CPU " + Affinity.getCpu());
ByteBuffer bb = ByteBuffer.allocateDirect(32 * 1024);
@@ -54,7 +57,6 @@ public class EchoServerMain {
Thread.yield();
ChronicleSocketChannel sc = nextSocket.getAndSet(null);
if (sc != null) {
-// System.out.println("Connected " + sc);
sockets.add(sc);
}
for (int i = 0; i < sockets.size(); i++) {
@@ -95,6 +97,7 @@ public class EchoServerMain {
}
}
}
+ }
}).start();
while (true) {
