From f285ab2756760fdc81868c4396e444aaa9ed19fa Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Wed, 14 Jan 2015 11:29:37 +0000 Subject: [PATCH] HCOLL-294 changed back to a spin loop but this time only for 10ms --- .../openhft/chronicle/map/TcpReplicator.java | 20 ++++++++++++++----- .../chronicle/map/TcpReplicationSoakTest.java | 1 - 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 7d1f5aa84..db4bc6c30 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -70,7 +70,8 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo private static final byte NOT_SET = (byte) HEARTBEAT.ordinal(); private static final Logger LOG = LoggerFactory.getLogger(TcpReplicator.class.getName()); private static final int BUFFER_SIZE = 0x100000; // 1MB - private static final int SPIN_LOOP_COUNT = 100000; + private static final int SPIN_LOOP_COUNT = 10; + public static final int SPIN_LOOP_TIME_IN_MILLIS = 100; private final SelectionKey[] selectionKeysStore = new SelectionKey[Byte.MAX_VALUE + 1]; // used to instruct the selector thread to set OP_WRITE on a key correlated by the bit index // in the bitset @@ -269,10 +270,19 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo /** * spin loops 100000 times first before calling the selector with timeout * - * @return + * @return The number of keys, possibly zero, whose ready-operation sets were updated * @throws IOException */ private int select() throws IOException { + + long start = System.currentTimeMillis(); + + while (System.currentTimeMillis() < start + SPIN_LOOP_TIME_IN_MILLIS) { + final int keys = selector.selectNow(); + if (keys != 0) + return keys; + } + return selector.select(selectorTimeout); } @@ -1624,7 +1634,7 @@ class StatelessServerConnector { final Function function = (Function) reader.readObject(); try { Object result = map.getMapped(key, function); - writeObject(writer,result); + writeObject(writer, result); } catch (Throwable e) { LOG.info("", e); return sendException(writer, sizeLocation, e); @@ -1641,7 +1651,7 @@ class StatelessServerConnector { final UnaryOperator unaryOperator = (UnaryOperator) reader.readObject(); try { Object result = map.putMapped(key, unaryOperator); - writeObject(writer,result); + writeObject(writer, result); } catch (Throwable e) { LOG.info("", e); return sendException(writer, sizeLocation, e); @@ -1748,7 +1758,7 @@ class StatelessServerConnector { final long remaining = writer.in().remaining(); try { String result = map.persistedDataVersion(); - writeObject(writer,result); + writeObject(writer, result); } catch (Throwable e) { return sendException(writer, sizeLocation, e); } diff --git a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java index 7b1aaee1e..13a4bbf25 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java @@ -96,7 +96,6 @@ public class TcpReplicationSoakTest { } - @Ignore @Test public void testSoakTestWithRandomData() throws IOException, InterruptedException { try {