You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by javadevmtl <ja...@gmail.com> on 2015/07/14 16:20:52 UTC
Best way to put in multiple caches.
I would like to do multiple puts to 4 different caches, what would be the
best way to do this in parallel?
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Best way to put in multiple caches.
Posted by dsetrakyan <ds...@apache.org>.
javadevmtl wrote
> And then I guess I can use a countdown latch to make sure all writes
> happened? Before returning response?
No need. If you call "future.get()" as Val suggested, then it will wait for
the write operation to complete. There is no need to add additional waiting.
D.
-----
D.
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645p708.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Best way to put in multiple caches.
Posted by javadevmtl <ja...@gmail.com>.
And then I guess I can use a countdown latch to make sure all writes
happened? Before returning response?
On Jul 23, 2015 4:08 PM, "vkulichenko [via Apache Ignite Users]" <
ml-node+s70518n695h82@n6.nabble.com> wrote:
> Hi,
>
> You can use asynchronous cache mode for this. In this mode cache executes
> all operations asynchronously and allows to get the future for the last
> operation via future() method.
>
> Here is the sample code:
>
> // Switch all caches to async mode.
> cache1 = cache1.withAsync();
> cache2 = cache2.withAsync();
> cache3 = cache3.withAsync();
> cache4 = cache4.withAsync();
>
> // Do all puts asynchronously.
> cache1.put(1, "a");
> cache2.put(2, "b");
> cache3.put(3, "c");
> cache4.put(4, "d");
>
> // Wait on all futures.
> cache1.future().get();
> cache2.future().get();
> cache3.future().get();
> cache4.future().get();
>
> -Val
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645p695.html
> To unsubscribe from Best way to put in multiple caches., click here
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=645&code=amF2YS5kZXYubXRsQGdtYWlsLmNvbXw2NDV8MTE3NjM4NTY0Mw==>
> .
> NAML
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645p706.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Best way to put in multiple caches.
Posted by vkulichenko <va...@gmail.com>.
Hi,
You can use asynchronous cache mode for this. In this mode cache executes
all operations asynchronously and allows to get the future for the last
operation via future() method.
Here is the sample code:
// Switch all caches to async mode.
cache1 = cache1.withAsync();
cache2 = cache2.withAsync();
cache3 = cache3.withAsync();
cache4 = cache4.withAsync();
// Do all puts asynchronously.
cache1.put(1, "a");
cache2.put(2, "b");
cache3.put(3, "c");
cache4.put(4, "d");
// Wait on all futures.
cache1.future().get();
cache2.future().get();
cache3.future().get();
cache4.future().get();
-Val
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645p695.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Best way to put in multiple caches.
Posted by javadevmtl <ja...@gmail.com>.
So write to multiple caches in parallel and then once finished writing to
each cache return response to "client"
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645p694.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Best way to put in multiple caches.
Posted by javadevmtl <ja...@gmail.com>.
Sorry for confusion I want to write single data to multiple cahces at same
time.
I.e:
cache1.put(somekey1, "xyz");
cache2.put(somekey2, "abc");
cache3.put(somekey3, "efg");
cache4.put(somekey4, "hello");
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645p693.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Best way to put in multiple caches.
Posted by Yakov Zhdanov <yz...@apache.org>.
Hi!
You can do:
1) use data streamer per each cache - See CacheDataStreamerExample
(org.apache.ignite.examples.datagrid.CacheDataStreamerExample)
while (haveDataToPut) {
for (i=0; i<4; i++) {
datastreamer[i].addData();
}
}
2) putAll
while (haveDataToPut) {
for (i=0; i<4; i++) {
cache[i].putAll() // provide convenient batches
}
Thanks!
--Yakov
2015-07-14 17:20 GMT+03:00 javadevmtl <ja...@gmail.com>:
> I would like to do multiple puts to 4 different caches, what would be the
> best way to do this in parallel?
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/Best-way-to-put-in-multiple-caches-tp645.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>