Net-client: perf tuning - make read buf the size of socket receive buf

This commit is contained in:
Jakub Valtar
2018-01-22 20:28:09 +01:00
parent fe465fe4de
commit d887779eb6

View File

@@ -219,7 +219,15 @@ public class Client implements Runnable {
@Override
public void run() {
byte[] readBuffer = new byte[2048]; // Ethernet MTU = 1500 B
byte[] readBuffer;
{ // make the read buffer same size as socket receive buffer so that
// we don't waste cycles calling listeners when there is more data waiting
int readBufferSize = 2 << 16; // 64 KB (default socket receive buffer size)
try {
readBufferSize = socket.getReceiveBufferSize();
} catch (SocketException ignore) { }
readBuffer = new byte[readBufferSize];
}
while (Thread.currentThread() == thread) {
try {
while (input != null) {