As it is stated in docs, Ignite provides system thread pool to process cache related operations. My issue is a data putting, but streaming and batch loading is not a solution, because that data comes from multiple clients through REST-queries, and fast write acknowledge for each query is required.
So I'm looking for a way to make cache.put() operation in parallel. And first question is - is it true that simple cache.put() is not executed in parallel? I found out that I can invoke Ignite custom ExecutorService as following:
ExecutorService exec = ignite.executorService();
<...>
exec.submit(new IgniteRunnable() {
@Override public void run() {
System.out.println("data put");
cache.put(i, somedataobj);
}});
and then all the put operations are executed in parallel on all nodes (because I see "data put" in console output on all nodes). But I think it is not a proper way to make put in parallel, because data firstly sent to worker node, only then is put.
Another way is using Java plain fixed thread pool like that:
ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
long startTime = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
int t = i;
DataClass dataobj = data().build();
exec.submit(new IgniteRunnable() {
@Override public void run() {
System.out.println("data put");
cache.put(t, dataobj);
}});
}
exec.shutdown();
exec.awaitTermination(0, TimeUnit.MILLISECONDS);
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
System.out.println(elapsedTime);
But then I get another problem - data get loaded very fast (I get small elapsedTime), but appears in cache much later (when I do cache -a through ignite visor, I see how cache size is growing)
How do I properly put data in parallel? How can I use Ignite System Thread Pool to put data in parallel?
elapsedTimebecause your code is borked. You call shutdown, you wait for zero milliseconds and then you decide that everything went great. There's no guarantee that all of yourIgniteRunnableswere even executed. - Kayaman