Use consistent hashing and thread local caches of StringBuilders.

This commit is contained in:
Peter Lawrey
2014-10-29 13:46:40 +00:00
parent 71a8d7452c
commit 4d7dd56c43
9 changed files with 62 additions and 45 deletions
@@ -245,12 +245,16 @@ public class CHMTest5 {
boolean compareAndSwapMaxNumberOfProcessesAllowed(int expected, int value);
@Deprecated()
void busyLockEntry() throws InterruptedException, IllegalStateException;
@Deprecated()
boolean tryLockNanosEntry(long nanos);
@Deprecated()
boolean tryLockEntry();
@Deprecated()
void unlockEntry() throws IllegalMonitorStateException;
}
}
@@ -55,7 +55,7 @@ public class EntryCountMapTest {
@Test
public void testSmall() throws Exception {
for (int i = 0; i < 60; i++) {
for (int i = 0; i < 6; i++) {
// regression test.
for (int s : new int[]{1, 2, 4, 8}) {
if (s <= 4)
@@ -77,7 +77,7 @@ public class EntryCountMapTest {
@Test
public void testMedium() throws Exception {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 1; i++) {
// regression test.
int s = 16;
testEntriesMaxSize(s, 512, 1000, i);
@@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import static net.openhft.chronicle.hash.StatelessBuilder.remoteAddress;
@@ -39,6 +40,8 @@ public class StatelessClientTest {
public static final int SIZE = 100000;
private static final AtomicInteger PORT_COUNTER = new AtomicInteger(58076);
public final int port = PORT_COUNTER.getAndIncrement();
@Test
@@ -52,13 +55,13 @@ public class StatelessClientTest {
{
statelessMap = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
.stateless(remoteAddress(new InetSocketAddress("localhost", port))).create();
}
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8076)).create();
.replicators((byte) 2, TcpReplicationConfig.of(port)).create();
}
@@ -95,13 +98,13 @@ public class StatelessClientTest {
{
statelessMap = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
.stateless(remoteAddress(new InetSocketAddress("localhost", port))).create();
}
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8076)).create();
.replicators((byte) 2, TcpReplicationConfig.of(port)).create();
}
@@ -136,13 +139,13 @@ public class StatelessClientTest {
{
statelessMap = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
.stateless(remoteAddress(new InetSocketAddress("localhost", port))).create();
}
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8076)).create();
.replicators((byte) 2, TcpReplicationConfig.of(port)).create();
}
@@ -175,7 +178,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8076)).create();
.replicators((byte) 2, TcpReplicationConfig.of(port)).create();
serverMap.put(10, "EXAMPLE-10");
}
@@ -185,7 +188,7 @@ public class StatelessClientTest {
{
statelessMap = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
.stateless(remoteAddress(new InetSocketAddress("localhost", port))).create();
Assert.assertEquals("EXAMPLE-10", statelessMap.get(10));
Assert.assertEquals(1, statelessMap.size());
@@ -208,13 +211,13 @@ public class StatelessClientTest {
{
statelessMap = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
.stateless(remoteAddress(new InetSocketAddress("localhost", port))).create();
}
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8076)).create();
.replicators((byte) 2, TcpReplicationConfig.of(port)).create();
serverMap.put(10, "EXAMPLE-10");
}
@@ -240,13 +243,13 @@ public class StatelessClientTest {
{
statelessMap = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
.stateless(remoteAddress(new InetSocketAddress("localhost", port))).create();
}
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8076)).create();
.replicators((byte) 2, TcpReplicationConfig.of(port)).create();
}
@@ -282,7 +285,7 @@ public class StatelessClientTest {
{
statelessMap1 = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8076))).create();
.stateless(remoteAddress(new InetSocketAddress("localhost", port))).create();
statelessMap2 = ChronicleMapBuilder.of(Integer
.class, CharSequence.class)
.stateless(remoteAddress(new InetSocketAddress("localhost", 8077))).create();
@@ -291,7 +294,7 @@ public class StatelessClientTest {
// server
{
serverMap1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8076)).create();
.replicators((byte) 2, TcpReplicationConfig.of(port)).create();
serverMap2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replicators((byte) 2, TcpReplicationConfig.of(8077)).create();
@@ -22,8 +22,10 @@ import net.openhft.lang.model.constraints.MaxSize;
public interface BondVOInterface {
/* add support for entry based locking */
@Deprecated()
void busyLockEntry() throws InterruptedException;
@Deprecated()
void unlockEntry();
long getIssueDate();
@@ -34,7 +34,6 @@ public class IntValue$$Native implements IntValue, BytesMarshallable, Byteable,
private long _offset;
public void setValue(int $) {
_bytes.writeInt(_offset + VALUE, $);
}
@@ -44,7 +43,6 @@ public class IntValue$$Native implements IntValue, BytesMarshallable, Byteable,
}
public void setOrderedValue(int $) {
_bytes.writeOrderedInt(_offset + VALUE, $);
}
@@ -55,20 +53,36 @@ public class IntValue$$Native implements IntValue, BytesMarshallable, Byteable,
public int addValue(int $) {
return _bytes.addInt(_offset + VALUE, $);
} public int addAtomicValue(int $) {
}
public int addAtomicValue(int $) {
return _bytes.addAtomicInt(_offset + VALUE, $);
} public boolean compareAndSwapValue(int _1, int _2) {
}
public boolean compareAndSwapValue(int _1, int _2) {
return _bytes.compareAndSwapInt(_offset + VALUE, _1, _2);
} public boolean tryLockNanosValue(long nanos) {
}
public boolean tryLockNanosValue(long nanos) {
return _bytes.tryLockNanosInt(_offset + VALUE, nanos);
} public boolean tryLockValue() {
}
public boolean tryLockValue() {
return _bytes.tryLockInt(_offset + VALUE);
} public void unlockValue() {
}
@Deprecated()
public void unlockValue() {
_bytes.unlockInt(_offset + VALUE);
} public void busyLockValue() throws InterruptedException {
}
@Deprecated()
public void busyLockValue() throws InterruptedException {
_bytes.busyLockInt(_offset + VALUE);
} @Override
public void copyFrom(net.openhft.lang.values.IntValue from) {
}
@Override
public void copyFrom(net.openhft.lang.values.IntValue from) {
setValue(from.getValue());
}
@@ -76,27 +90,33 @@ public class IntValue$$Native implements IntValue, BytesMarshallable, Byteable,
public void writeMarshallable(Bytes out) {
out.writeInt(getValue());
}
@Override
public void readMarshallable(Bytes in) {
setValue(in.readInt());
}
@Override
public void bytes(Bytes bytes, long offset) {
this._bytes = bytes;
this._offset = offset;
}
@Override
public Bytes bytes() {
return _bytes;
}
@Override
public long offset() {
return _offset;
}
@Override
public int maxSize() {
return 4;
}
public int hashCode() {
long lhc = longHashCode();
return (int) ((lhc >>> 32) ^ lhc);
@@ -111,7 +131,7 @@ public class IntValue$$Native implements IntValue, BytesMarshallable, Byteable,
if (!(o instanceof IntValue)) return false;
IntValue that = (IntValue) o;
if(!isEqual(getValue(), that.getValue())) return false;
if (!isEqual(getValue(), that.getValue())) return false;
return true;
}