use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteCommunicationBalanceTest method testBalance2.
/**
* @throws Exception If failed.
*/
public void testBalance2() throws Exception {
System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "1000");
try {
startGridsMultiThreaded(5);
client = true;
startGridsMultiThreaded(5, 5);
for (int i = 0; i < 5; i++) {
log.info("Iteration: " + i);
final AtomicInteger idx = new AtomicInteger();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
Ignite node = ignite(idx.incrementAndGet() % 10);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int msgs = rnd.nextInt(500, 600);
for (int i = 0; i < msgs; i++) {
int sndTo = rnd.nextInt(10);
ClusterNode sntToNode = node.cluster().node(ignite(sndTo).cluster().localNode().id());
IgniteCompute compute = node.compute(node.cluster().forNode(sntToNode));
compute.call(new DummyCallable(new byte[rnd.nextInt(rnd.nextInt(256, 1024))]));
}
return null;
}
}, 30, "test-thread");
waitNioBalanceStop(G.allGrids(), 10_000);
}
} finally {
System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "");
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteCommunicationBalanceTest method testBalance1.
/**
* @throws Exception If failed.
*/
public void testBalance1() throws Exception {
if (sslEnabled())
return;
System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "5000");
try {
selectors = 4;
final int SRVS = 6;
startGridsMultiThreaded(SRVS);
client = true;
final Ignite client = startGrid(SRVS);
for (int i = 0; i < SRVS; i++) {
ClusterNode node = client.cluster().node(ignite(i).cluster().localNode().id());
client.compute(client.cluster().forNode(node)).call(new DummyCallable(null));
}
waitNioBalanceStop(Collections.singletonList(client), 10_000);
final GridNioServer srv = GridTestUtils.getFieldValue(client.configuration().getCommunicationSpi(), "nioSrvr");
ThreadLocalRandom rnd = ThreadLocalRandom.current();
long readMoveCnt1 = srv.readerMoveCount();
long writeMoveCnt1 = srv.writerMoveCount();
int prevNodeIdx = -1;
for (int iter = 0; iter < 10; iter++) {
int nodeIdx = rnd.nextInt(SRVS);
while (prevNodeIdx == nodeIdx) nodeIdx = rnd.nextInt(SRVS);
prevNodeIdx = nodeIdx;
log.info("Iteration [iter=" + iter + ", node=" + nodeIdx + ']');
final long readMoveCnt = readMoveCnt1;
final long writeMoveCnt = writeMoveCnt1;
final int nodeIdx0 = nodeIdx;
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
byte[] data = new byte[100_000];
for (int j = 0; j < 10; j++) {
for (int i = 0; i < SRVS; i++) {
ClusterNode node = client.cluster().node(ignite(i).cluster().localNode().id());
IgniteCompute compute = client.compute(client.cluster().forNode(node));
compute.call(new DummyCallable(i == nodeIdx0 ? data : null));
}
}
if (usePairedConnections())
return srv.readerMoveCount() > readMoveCnt && srv.writerMoveCount() > writeMoveCnt;
else
return srv.readerMoveCount() > readMoveCnt || srv.writerMoveCount() > writeMoveCnt;
}
}, 30_000);
waitNioBalanceStop(Collections.singletonList(client), 30_000);
long readMoveCnt2 = srv.readerMoveCount();
long writeMoveCnt2 = srv.writerMoveCount();
log.info("Move counts [rc1=" + readMoveCnt1 + ", wc1=" + writeMoveCnt1 + ", rc2=" + readMoveCnt2 + ", wc2=" + writeMoveCnt2 + ']');
if (usePairedConnections()) {
assertTrue(readMoveCnt2 > readMoveCnt1);
assertTrue(writeMoveCnt2 > writeMoveCnt1);
} else
assertTrue(readMoveCnt2 > readMoveCnt1 || writeMoveCnt2 > writeMoveCnt1);
readMoveCnt1 = readMoveCnt2;
writeMoveCnt1 = writeMoveCnt2;
}
waitNioBalanceStop(G.allGrids(), 10_000);
} finally {
System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "");
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteVariousConnectionNumberTest method runOperations.
/**
* @param time Execution time.
* @throws Exception If failed.
*/
private void runOperations(final long time) throws Exception {
final AtomicInteger idx = new AtomicInteger();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
Ignite node = ignite(idx.getAndIncrement() % NODES);
IgniteCache cache = node.cache(DEFAULT_CACHE_NAME);
long stopTime = U.currentTimeMillis() + time;
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (U.currentTimeMillis() < stopTime) {
cache.put(rnd.nextInt(10_000), 0);
node.compute().broadcast(new DummyJob());
}
return null;
}
}, NODES * 10, "test-thread");
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class CacheSerializableTransactionsTest method testNoOptimisticExceptionOnChangingTopology.
/**
* @throws Exception If failed.
*/
public void testNoOptimisticExceptionOnChangingTopology() throws Exception {
if (FAST)
return;
final AtomicBoolean finished = new AtomicBoolean();
final List<String> cacheNames = new ArrayList<>();
Ignite srv = ignite(1);
try {
{
CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
ccfg.setName("cache1");
ccfg.setRebalanceMode(SYNC);
srv.createCache(ccfg);
cacheNames.add(ccfg.getName());
}
{
// Store enabled.
CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, true, false);
ccfg.setName("cache2");
ccfg.setRebalanceMode(SYNC);
srv.createCache(ccfg);
cacheNames.add(ccfg.getName());
}
{
// Eviction.
CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
ccfg.setName("cache3");
ccfg.setRebalanceMode(SYNC);
LruEvictionPolicy plc = new LruEvictionPolicy();
plc.setMaxSize(100);
ccfg.setEvictionPolicy(plc);
ccfg.setOnheapCacheEnabled(true);
srv.createCache(ccfg);
cacheNames.add(ccfg.getName());
}
IgniteInternalFuture<?> restartFut = restartFuture(finished, null);
List<IgniteInternalFuture<?>> futs = new ArrayList<>();
final int KEYS_PER_THREAD = 100;
for (int i = 1; i < SRVS + CLIENTS; i++) {
final Ignite node = ignite(i);
final int minKey = i * KEYS_PER_THREAD;
final int maxKey = minKey + KEYS_PER_THREAD;
// Threads update non-intersecting keys, optimistic exception should not be thrown.
futs.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
log.info("Started update thread [node=" + node.name() + ", minKey=" + minKey + ", maxKey=" + maxKey + ']');
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
List<IgniteCache<Integer, Integer>> caches = new ArrayList<>();
for (String cacheName : cacheNames) caches.add(node.<Integer, Integer>cache(cacheName));
assertEquals(3, caches.size());
int iter = 0;
while (!finished.get()) {
int keyCnt = rnd.nextInt(1, 10);
final Set<Integer> keys = new LinkedHashSet<>();
while (keys.size() < keyCnt) keys.add(rnd.nextInt(minKey, maxKey));
for (final IgniteCache<Integer, Integer> cache : caches) {
doInTransaction(node, OPTIMISTIC, SERIALIZABLE, new Callable<Void>() {
@Override
public Void call() throws Exception {
for (Integer key : keys) randomOperation(rnd, cache, key);
return null;
}
});
}
if (iter % 100 == 0)
log.info("Iteration: " + iter);
iter++;
}
return null;
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
}, "update-thread-" + i));
}
U.sleep(60_000);
finished.set(true);
restartFut.get();
for (IgniteInternalFuture<?> fut : futs) fut.get();
} finally {
finished.set(true);
for (String cacheName : cacheNames) destroyCache(cacheName);
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class CacheSerializableTransactionsTest method checkReadWriteTransactionsNoDeadlock.
/**
* @param multiNode Multi-node test flag.
* @throws Exception If failed.
*/
private void checkReadWriteTransactionsNoDeadlock(final boolean multiNode) throws Exception {
final Ignite ignite0 = ignite(0);
for (final CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
logCacheInfo(ccfg);
ignite0.createCache(ccfg);
try {
final long stopTime = U.currentTimeMillis() + 10_000;
final AtomicInteger idx = new AtomicInteger();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
Ignite ignite = multiNode ? ignite(idx.incrementAndGet() % (SRVS + CLIENTS)) : ignite0;
IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (U.currentTimeMillis() < stopTime) {
try {
try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
for (int i = 0; i < 10; i++) {
Integer key = rnd.nextInt(30);
if (rnd.nextBoolean())
cache.get(key);
else
cache.put(key, key);
}
tx.commit();
}
} catch (TransactionOptimisticException ignore) {
// No-op.
}
}
return null;
}
}, 32, "test-thread");
} finally {
destroyCache(ccfg.getName());
}
}
}
Aggregations