Ensure Nagle is always off.

This commit is contained in:
Peter Lawrey
2014-11-12 19:13:29 +00:00
parent 2169252dd1
commit 82b55fbd78
4 changed files with 91 additions and 1 deletions
@@ -0,0 +1,87 @@
/*
* Copyright 2014 Higher Frequency Trading
*
* http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.map.example;
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
/**
* Created by peter on 12/11/14.
*/
public class ServersMapMain {
static final int port = Integer.getInteger("port", 8989);
static final int entries = Integer.getInteger("entries", 10000);
static final int runs = Integer.getInteger("runs", 5);
public static void startServer() throws IOException {
File file = File.createTempFile("testServersMapMain", ".deleteme");
file.deleteOnExit();
final ChronicleMap<byte[], byte[]> serverMap = ChronicleMapBuilder.of(byte[].class, byte[].class)
.putReturnsNull(true)
.entrySize(50)
.replication((byte) 2, TcpTransportAndNetworkConfig.of(port))
.createPersistedTo(file);
System.out.println("Server started");
System.in.read();
serverMap.close();
}
public static void startRemoteClient(String hostname) throws IOException {
final ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder.of(
byte[].class, byte[].class)
.putReturnsNull(true)
.statelessClient(new InetSocketAddress(hostname, port)).create();
ByteBuffer key = ByteBuffer.allocate(8);
ByteBuffer value = ByteBuffer.allocate(32);
double lastAveragePut = Double.POSITIVE_INFINITY, lastAverageGet = Double.POSITIVE_INFINITY;
for (int i = 0; i < runs; i++) {
long puts = 0, gets = 0;
for (int j = 0; j < entries; j++) {
key.putLong(0, j);
value.putLong(0, j);
long t1 = System.nanoTime();
map.put(key.array(), value.array());
long t2 = System.nanoTime();
map.get(key.array());
long t3 = System.nanoTime();
puts += t2 - t1;
gets += t3 - t2;
if (t2 - t1 > lastAveragePut * 10 || t3 - t2 > lastAverageGet * 10)
System.out.printf("Took put/get took %.1f/%.1f us%n", (t2 - t1) / 1e3, (t3 - t2) / 1e3);
}
lastAveragePut = puts / entries;
lastAverageGet = gets / entries;
System.out.printf("Average took put/get took %.1f/%.1f us%n", lastAveragePut / 1e3, lastAverageGet / 1e3);
}
}
public static void main(String[] args) throws IOException {
if (args.length > 0)
startRemoteClient(args[0]);
else
startServer();
}
}