use of org.jsr166.ThreadLocalRandom8 in project ignite by apache.
the class IgniteCache150ClientsTest method test150Clients.
/**
* @throws Exception If failed.
*/
public void test150Clients() throws Exception {
Ignite srv = startGrid(0);
assertFalse(srv.configuration().isClientMode());
final int CLIENTS = 150;
final AtomicInteger idx = new AtomicInteger(1);
final CountDownLatch latch = new CountDownLatch(CLIENTS);
final List<String> cacheNames = new ArrayList<>();
for (int i = 0; i < CACHES; i++) cacheNames.add("cache-" + i);
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
boolean cnt = false;
try {
Ignite ignite = startGrid(idx.getAndIncrement());
assertTrue(ignite.configuration().isClientMode());
assertTrue(ignite.cluster().localNode().isClient());
latch.countDown();
cnt = true;
log.info("Started [node=" + ignite.name() + ", left=" + latch.getCount() + ']');
ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
while (latch.getCount() > 0) {
Thread.sleep(1000);
IgniteCache<Object, Object> cache = ignite.cache(cacheNames.get(rnd.nextInt(0, CACHES)));
Integer key = rnd.nextInt(0, 100_000);
cache.put(key, 0);
assertNotNull(cache.get(key));
}
return null;
} finally {
if (!cnt)
latch.countDown();
}
}
}, CLIENTS, "start-client");
fut.get();
log.info("Started all clients.");
checkNodes(CLIENTS + 1);
}
use of org.jsr166.ThreadLocalRandom8 in project ignite by apache.
the class IgniteDataStreamerPerformanceTest method doTest.
/**
* @throws Exception If failed.
*/
private void doTest() throws Exception {
System.gc();
System.gc();
System.gc();
try {
useCache = true;
startGridsMultiThreaded(GRID_CNT);
useCache = false;
Ignite ignite = startGrid();
final IgniteDataStreamer<Integer, String> ldr = ignite.dataStreamer(DEFAULT_CACHE_NAME);
ldr.perNodeBufferSize(8192);
ldr.receiver(DataStreamerCacheUpdaters.<Integer, String>batchedSorted());
ldr.autoFlushFrequency(0);
final LongAdder8 cnt = new LongAdder8();
long start = U.currentTimeMillis();
Thread t = new Thread(new Runnable() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException ignored) {
break;
}
info(">>> Adds/sec: " + cnt.sumThenReset() / 10);
}
}
});
t.setDaemon(true);
t.start();
//Runtime.getRuntime().availableProcessors();
int threadNum = 2;
multithreaded(new Callable<Object>() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public Object call() throws Exception {
ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
while (true) {
int i = rnd.nextInt(ENTRY_CNT);
ldr.addData(i, vals[rnd.nextInt(vals.length)]);
cnt.increment();
}
}
}, threadNum, "loader");
info("Closing loader...");
ldr.close(false);
long duration = U.currentTimeMillis() - start;
info("Finished performance test. Duration: " + duration + "ms.");
} finally {
stopAllGrids();
}
}
use of org.jsr166.ThreadLocalRandom8 in project ignite by apache.
the class IgfsSizeSelfTest method write.
/**
* Perform write of the files.
*
* @return Collection of written file descriptors.
* @throws Exception If failed.
*/
private Collection<IgfsFile> write() throws Exception {
Collection<IgfsFile> res = new HashSet<>(FILES_CNT, 1.0f);
ThreadLocalRandom8 rand = ThreadLocalRandom8.current();
for (int i = 0; i < FILES_CNT; i++) {
// Create empty file locally.
IgfsPath path = new IgfsPath("/file-" + i);
igfs(0).create(path, false).close();
IgfsMetaManager meta = igfs(0).context().meta();
IgniteUuid fileId = meta.fileId(path);
// Calculate file blocks.
int fileSize = rand.nextInt(MAX_FILE_SIZE);
int fullBlocks = fileSize / BLOCK_SIZE;
int remainderSize = fileSize % BLOCK_SIZE;
Collection<IgfsBlock> blocks = new ArrayList<>(fullBlocks + remainderSize > 0 ? 1 : 0);
for (int j = 0; j < fullBlocks; j++) blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, j), BLOCK_SIZE));
if (remainderSize > 0)
blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, fullBlocks), remainderSize));
IgfsFile file = new IgfsFile(path, fileSize, blocks);
// Actual write.
for (IgfsBlock block : blocks) {
IgfsOutputStream os = igfs(0).append(path, false);
os.write(chunk(block.length()));
os.close();
}
// Add written file to the result set.
res.add(file);
}
return res;
}
use of org.jsr166.ThreadLocalRandom8 in project ignite by apache.
the class GridContinuousOperationsLoadTest method main.
/**
* Main method.
*
* @param args Command line arguments.
* @throws Exception If error occurs.
*/
public static void main(String[] args) throws Exception {
final String cfgPath = args.length > 0 ? args[0] : "examples/config/example-cache.xml";
final String cacheName = getStringProperty(CACHE_NAME, "partitioned");
final Integer valSize = getIntProperty(VALUE_SIZE, 1024);
final Integer threadsCnt = getIntProperty(THREADS_CNT, 8);
final Integer testDurSec = getIntProperty(TEST_DUR_SEC, 180);
final Integer filterSkipProb = getIntProperty("FILTER_SKIP_PROBABILITY", 10, new C1<Integer, String>() {
@Nullable
@Override
public String apply(Integer val) {
if (val < 0 || val > 100)
return "The value should be between 1 and 100.";
return null;
}
});
final boolean useQry = getBooleanProperty("IGNITE_USE_QUERIES", true);
final int bufSize = getIntProperty("IGNITE_BUFFER_SIZE", 1);
final long timeInterval = getLongProperty("IGNITE_TIME_INTERVAL", 0);
final int parallelCnt = getIntProperty("IGNITE_PARALLEL_COUNT", 8);
final int keyRange = getIntProperty("IGNITE_KEY_RANGE", 100000);
final long updSleepMs = getLongProperty("IGNITE_UPDATE_SLEEP_MS", 0);
final long filterSleepMs = getLongProperty("IGNITE_FILTER_SLEEP_MS", 0);
final long cbSleepMs = getLongProperty("IGNITE_CALLBACK_SLEEP_MS", 0);
X.println("The test will start with the following parameters:");
dumpProperties(System.out);
try (Ignite ignite = Ignition.start(cfgPath)) {
final IgniteCache<Object, Object> cache = ignite.cache(cacheName);
if (cache == null)
throw new IgniteCheckedException("Cache is not configured: " + cacheName);
// Continuous query manager, used to monitor queue size.
final CacheContinuousQueryManager contQryMgr = ((IgniteKernal) ignite).context().cache().cache(cacheName).context().continuousQueries();
if (contQryMgr == null)
throw new IgniteCheckedException("Could not access CacheContinuousQueryManager");
// Stop flag.
final AtomicBoolean stop = new AtomicBoolean();
// Callback counter.
final AtomicLong cbCntr = new AtomicLong();
// Update counter.
final AtomicLong updCntr = new AtomicLong();
for (int i = 0; i < parallelCnt; i++) {
if (useQry) {
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
if (cbSleepMs > 0) {
try {
U.sleep(cbSleepMs);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
for (CacheEntryEvent<?, ?> ignored : evts) cbCntr.incrementAndGet();
}
});
qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {
@Override
public boolean evaluate(CacheEntryEvent<?, ?> evt) {
if (filterSleepMs > 0) {
try {
U.sleep(filterSleepMs);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
return Math.random() * 100 >= filterSkipProb;
}
});
qry.setPageSize(bufSize);
qry.setTimeInterval(timeInterval);
cache.query(qry);
} else {
ignite.events().remoteListen(bufSize, timeInterval, true, new PX2<UUID, Event>() {
@Override
public boolean applyx(UUID uuid, Event evt) throws IgniteInterruptedCheckedException {
if (cbSleepMs > 0)
U.sleep(cbSleepMs);
cbCntr.incrementAndGet();
// Continue listening.
return true;
}
}, new PX1<Event>() {
@Override
public boolean applyx(Event evt) throws IgniteInterruptedCheckedException {
if (filterSleepMs > 0)
U.sleep(filterSleepMs);
return Math.random() * 100 >= filterSkipProb;
}
}, EVT_CACHE_OBJECT_PUT);
}
}
// Start collector thread.
startDaemon(new Runnable() {
@Override
public void run() {
try {
while (!stop.get() && !Thread.currentThread().isInterrupted()) {
long cbCntr0 = cbCntr.get();
long updCntr0 = updCntr.get();
U.sleep(1000);
long cbDelta = cbCntr.get() - cbCntr0;
long updDelta = updCntr.get() - updCntr0;
X.println("Stats [entriesPerSec=" + cbDelta + ", updatesPerSec=" + updDelta + ']');
}
} catch (IgniteInterruptedCheckedException ignored) {
// No-op.
}
}
});
X.println("Starting " + threadsCnt + " generator thread(s).");
// Start generator threads.
IgniteInternalFuture<Long> genFut = runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
byte[] val = new byte[valSize];
ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
while (!stop.get() && !Thread.currentThread().isInterrupted()) {
Integer key = rnd.nextInt(keyRange);
cache.put(key, val);
updCntr.incrementAndGet();
if (updSleepMs > 0)
U.sleep(updSleepMs);
}
return true;
}
}, threadsCnt, "load-test-generator");
U.sleep(testDurSec * 1000);
stop.set(true);
genFut.get();
}
}
Aggregations