use of org.infinispan.distribution.ch.impl.HashFunctionPartitioner in project infinispan by infinispan.
the class StateReceiverTest method createLocalizedCacheTopology.
private LocalizedCacheTopology createLocalizedCacheTopology(int numberOfNodes) {
ConsistentHash hash = createConsistentHash(numberOfNodes);
CacheTopology topology = new CacheTopology(-1, -1, hash, null, CacheTopology.Phase.NO_REBALANCE, hash.getMembers(), null);
return new LocalizedCacheTopology(CacheMode.DIST_SYNC, topology, new HashFunctionPartitioner(), hash.getMembers().get(0), true);
}
use of org.infinispan.distribution.ch.impl.HashFunctionPartitioner in project infinispan by infinispan.
the class StateProviderTest method test1.
public void test1() {
// create list of 6 members
List<Address> members1 = Arrays.asList(A, B, C, D, E, F);
List<Address> members2 = new ArrayList<>(members1);
members2.remove(A);
members2.remove(F);
members2.add(G);
// create CHes
KeyPartitioner keyPartitioner = new HashFunctionPartitioner(StateProviderTest.NUM_SEGMENTS);
DefaultConsistentHashFactory chf = new DefaultConsistentHashFactory();
DefaultConsistentHash ch1 = chf.create(2, StateProviderTest.NUM_SEGMENTS, members1, null);
DefaultConsistentHash ch2 = chf.updateMembers(ch1, members2, null);
// create dependencies
when(rpcManager.getAddress()).thenReturn(A);
when(rpcManager.invokeCommand(any(Address.class), any(), any(), any())).thenReturn(new CompletableFuture<>());
// create state provider
StateProviderImpl stateProvider = new StateProviderImpl();
TestingUtil.inject(stateProvider, configuration, rpcManager, commandsFactory, cacheNotifier, persistenceManager, dataContainer, transactionTable, stateTransferLock, distributionManager, ef, keyPartitioner, TransactionOriginatorChecker.LOCAL);
stateProvider.start();
final List<InternalCacheEntry> cacheEntries = new ArrayList<>();
Object key1 = new TestKey("key1", 0, keyPartitioner);
Object key2 = new TestKey("key2", 0, keyPartitioner);
cacheEntries.add(new ImmortalCacheEntry(key1, "value1"));
cacheEntries.add(new ImmortalCacheEntry(key2, "value2"));
when(dataContainer.iterator()).thenAnswer(invocation -> cacheEntries.iterator());
when(transactionTable.getLocalTransactions()).thenReturn(Collections.emptyList());
when(transactionTable.getRemoteTransactions()).thenReturn(Collections.emptyList());
CacheTopology simpleTopology = new CacheTopology(1, 1, ch1, ch1, ch1, CacheTopology.Phase.READ_OLD_WRITE_ALL, ch1.getMembers(), persistentUUIDManager.mapAddresses(ch1.getMembers()));
this.cacheTopology = new LocalizedCacheTopology(CacheMode.DIST_SYNC, simpleTopology, keyPartitioner, A, true);
stateProvider.onTopologyUpdate(this.cacheTopology, false);
log.debug("ch1: " + ch1);
IntSet segmentsToRequest = IntSets.from(ch1.getSegmentsForOwner(members1.get(0)));
CompletionStage<List<TransactionInfo>> transactionsStage = stateProvider.getTransactionsForSegments(members1.get(0), 1, segmentsToRequest);
List<TransactionInfo> transactions = CompletionStages.join(transactionsStage);
assertEquals(0, transactions.size());
CompletionStage<List<TransactionInfo>> transactionsStage2 = stateProvider.getTransactionsForSegments(members1.get(0), 1, SmallIntSet.of(2, StateProviderTest.NUM_SEGMENTS));
Exceptions.expectExecutionException(IllegalArgumentException.class, transactionsStage2.toCompletableFuture());
verifyNoMoreInteractions(stateTransferLock);
when(dataContainer.iterator(any())).thenReturn(cacheEntries.iterator());
when(persistenceManager.publishEntries(any(IntSet.class), any(), anyBoolean(), anyBoolean(), any())).thenReturn(Flowable.empty());
stateProvider.startOutboundTransfer(F, 1, IntSets.immutableSet(0), true);
assertTrue(stateProvider.isStateTransferInProgress());
log.debug("ch2: " + ch2);
simpleTopology = new CacheTopology(2, 1, ch2, ch2, ch2, CacheTopology.Phase.READ_OLD_WRITE_ALL, ch2.getMembers(), persistentUUIDManager.mapAddresses(ch2.getMembers()));
this.cacheTopology = new LocalizedCacheTopology(CacheMode.DIST_SYNC, simpleTopology, keyPartitioner, A, true);
stateProvider.onTopologyUpdate(this.cacheTopology, true);
assertFalse(stateProvider.isStateTransferInProgress());
stateProvider.startOutboundTransfer(D, 1, IntSets.immutableSet(0), true);
assertTrue(stateProvider.isStateTransferInProgress());
stateProvider.stop();
assertFalse(stateProvider.isStateTransferInProgress());
}
use of org.infinispan.distribution.ch.impl.HashFunctionPartitioner in project infinispan by infinispan.
the class ConsistentHashPerfTest method doTestDistribution.
private void doTestDistribution(int numKeys, int numNodes, List<Object> keys) {
ConsistentHash ch = createNewConsistentHash(createAddresses(numNodes));
Map<Address, Integer> distribution = new HashMap<>();
KeyPartitioner keyPartitioner = new HashFunctionPartitioner(ch.getNumSegments());
for (Object key : keys) {
int segment = keyPartitioner.getSegment(key);
Address a = ch.locateOwnersForSegment(segment).get(0);
if (distribution.containsKey(a)) {
int i = distribution.get(a);
distribution.put(a, i + 1);
} else {
distribution.put(a, 1);
}
}
System.out.printf("\nTesting distribution with %d keys, %d nodes\n", numKeys, numNodes);
// System.out.println("" + distribution);
// calc numbers
ArrayList<Integer> counts = new ArrayList<Integer>(distribution.values());
Collections.sort(counts);
// instead we add a 0 for all the nonexistent keys in the distribution map and do the calculations
for (int i = 0; i < numNodes - counts.size(); i++) counts.add(0, 0);
double mean = 0;
int sum = 0;
for (Integer count : counts) sum += count;
assert sum == numKeys;
mean = sum / numNodes;
double variance = 0;
for (Integer count : counts) variance += (count - mean) * (count - mean);
double stdDev = sqrt(variance);
double avgAbsDev = 0;
for (Integer count : counts) avgAbsDev += abs(count - mean);
avgAbsDev /= numNodes;
int median = counts.get(numNodes / 2);
ArrayList<Integer> medianDevs = new ArrayList<Integer>(numNodes);
for (Integer count : counts) medianDevs.add(abs(count - median));
Collections.sort(medianDevs);
int medianAbsDev = medianDevs.get(numNodes / 2);
System.out.printf("Mean = %f, median = %d\n", mean, median);
System.out.printf("Standard deviation = %.3f, or %.3f%%\n", stdDev, stdDev / mean * 100);
System.out.printf("Average absolute deviation = %.3f, or %.3f%%\n", avgAbsDev, avgAbsDev / mean * 100);
System.out.printf("Median absolute deviation = %d or %.3f%%\n", medianAbsDev, (double) medianAbsDev / mean * 100);
}
use of org.infinispan.distribution.ch.impl.HashFunctionPartitioner in project infinispan by infinispan.
the class ConsistentHashPerfTest method doPerfTest.
private Long doPerfTest(int numNodes, int numOwners, int iterations) {
ConsistentHash ch = createNewConsistentHash(createAddresses(numNodes));
int dummy = 0;
long start = System.nanoTime();
KeyPartitioner keyPartitioner = new HashFunctionPartitioner(ch.getNumSegments());
for (int i = 0; i < iterations; i++) {
Object key = i;
int segment = keyPartitioner.getSegment(key);
dummy += ch.locateOwnersForSegment(segment).size();
}
long duration = System.nanoTime() - start;
assertEquals(dummy, iterations * min(numOwners, numNodes));
return duration;
}
use of org.infinispan.distribution.ch.impl.HashFunctionPartitioner in project infinispan by infinispan.
the class TopologyAwareOwnershipStatistics method setUp.
@BeforeMethod()
public void setUp() {
chf = createConsistentHashFactory();
chMembers = new ArrayList<>(ADDRESS_COUNT);
capacityFactors = null;
testAddresses = new TestTopologyAwareAddress[ADDRESS_COUNT];
for (int i = 0; i < ADDRESS_COUNT; i++) {
testAddresses[i] = new TestTopologyAwareAddress(i * 100);
testAddresses[i].setName(Character.toString((char) ('A' + i)));
}
keyPartitioner = new HashFunctionPartitioner(numSegments);
}
Aggregations