HCOLL-294 changed back to a spin loop but this time only for 10ms

This commit is contained in:
Rob Austin
2015-01-14 11:29:37 +00:00
parent efeab00079
commit f285ab2756
2 changed files with 15 additions and 6 deletions
@@ -70,7 +70,8 @@ final class TcpReplicator<K, V> 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<K, V> 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<K, V> {
final Function<V, ?> function = (Function<V, ?>) 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<K, V> {
final UnaryOperator<V> unaryOperator = (UnaryOperator<V>) 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<K, V> {
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);
}