use of org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet in project ignite by apache.
the class GridBoundedConcurrentLinkedHashSetLoadTest method main.
/**
* @param args Arguments.
*/
public static void main(String[] args) throws Exception {
QueuePolicy qPlc = args.length > 0 ? QueuePolicy.valueOf(args[0]) : SINGLE_Q;
int threadCnt = args.length > 1 ? Integer.valueOf(args[1]) : Runtime.getRuntime().availableProcessors();
X.println("Queue policy: " + qPlc);
X.println("Threads: " + threadCnt);
ExecutorService pool = Executors.newFixedThreadPool(threadCnt);
final Collection<IgniteUuid> set = new GridBoundedConcurrentLinkedHashSet<>(10240, 32, 0.75f, 128, qPlc);
X.println("Set: " + set);
final LongAdder execCnt = new LongAdder();
final AtomicBoolean finish = new AtomicBoolean();
// Thread that measures and outputs performance statistics.
Thread collector = new Thread(new Runnable() {
@SuppressWarnings({ "BusyWait" })
@Override
public void run() {
GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
try {
while (!finish.get()) {
Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
X.println(">>> Tasks/s: " + curTasksPerSec);
avgTasksPerSec.update(curTasksPerSec);
}
} catch (InterruptedException ignored) {
X.println(">>> Interrupted.");
Thread.currentThread().interrupt();
}
}
});
collector.start();
Collection<Callable<Object>> producers = new ArrayList<>(threadCnt);
for (int i = 0; i < threadCnt; i++) producers.add(new Callable<Object>() {
@Override
public Object call() throws Exception {
UUID id = UUID.randomUUID();
try {
while (!finish.get()) {
set.add(IgniteUuid.fromUuid(id));
execCnt.increment();
}
return null;
} catch (Throwable t) {
t.printStackTrace();
throw new Exception(t);
} finally {
X.println("Thread finished.");
}
}
});
pool.invokeAll(producers);
}
Aggregations