Re: Replace compute.affinityCall with cache.invoke

classic Classic list List threaded Threaded
5 messages Options
Sergi Vladykin Sergi Vladykin
Reply | Threaded
Open this post in threaded view
|

Re: Replace compute.affinityCall with cache.invoke

Could you please provide links to your code instead of pasting it in email, it is really hard to follow.

Sergi

2015-08-31 17:28 GMT+03:00 javadevmtl <[hidden email]>:
Running 1.3.0 on 2 nodes.

I have the below code which works absolutely great. I can get 11,000 full
business requests with 2ms latency (including network).

Wondering if I should replace compute.affinityCall() with cache.invoke()?
Inside the EntryProcessor if the key does not exist yet. Can we do a
cache.put()?
Does cache.invoke also collocate with the key?


                                final Context ctx = vertx.getOrCreateContext();

                                compute.<HashMap&lt;String, HashSet&lt;String>>>affinityCall(CACHE_NAME,
key, () -> {
                                        HashMap<String, HashSet&lt;String>> params =
cache.localPeek(acctNumber, CachePeekMode.OFFHEAP);

                                        if(params == null) {
                                                params = new HashMap<String, HashSet&lt;String>>();

                                                params.put("field1", newHashSet(field1));
                                                params.put("field2", newHashSet(field2));
                                                params.put("field3", newHashSet(field3));
                                                params.put("field4", newHashSet(field4));
                                                params.put("field5", newHashSet(field5));
                                                params.put("field6", newHashSet(field6));
                                                params.put("field7", newHashSet(field7));
                                                params.put("field8", newHashSet(field8));
                                                params.put("field9", newHashSet(field9));
                                        } else {
                                                params.get("field1").add(field1);
                                                params.get("field2").add(field2);
                                                params.get("field3").add(field3);
                                                params.get("field4").add(field4);
                                                params.get("field5").add(field5);
                                                params.get("field6").add(field6);
                                                params.get("field7").add(field7);
                                                params.get("field8").add(field8);
                                                params.get("field9").add(field9);
                                        }


                                        cache.put(key, params);

                                        return params;
                                });

                                compute.<HashMap&lt;String, HashSet&lt;String>>>future().listen(af -> {

                                        final HashMap<String, HashSet&lt;String>> newParams = af.get();

                                        String counts = acctNumber + "="
                                        + newParams.get("name").size() + ","
                                        + newParams.get("acctNumber").size() + ","
                                        + newParams.get("acctNumber2").size() + ","
                                                        + newParams.get("address").size() + ","
                                                        + newParams.get("phone").size() + ","
                                                        + newParams.get("email").size() + ","
                                                        + newParams.get("ip").size() + ","
                                                        + newParams.get("deviceId").size() + ","
                                                        + newParams.get("shipToAddress").size()
                                                        ;
                                        final JsonObject response = new JsonObject().put("result", counts);

                                        ctx.runOnContext(ch -> {
                                                rh.reply(response);
                                        });
                                });




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Replace-compute-affinityCall-with-cache-invoke-tp1210.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

javadevmtl javadevmtl
Reply | Threaded
Open this post in threaded view
|

Re: Replace compute.affinityCall with cache.invoke

Sure, and actually can we delete this thread please?

I'll repost...
javadevmtl javadevmtl
Reply | Threaded
Open this post in threaded view
|

Re: Replace compute.affinityCall with cache.invoke

Is there a way to remove this thread please? I tried to delete prior to posting so I don't know why it leaves us the option to delete...

Thanks
dsetrakyan dsetrakyan
Reply | Threaded
Open this post in threaded view
|

Re: Replace compute.affinityCall with cache.invoke

This post was updated on .
In reply to this post by Sergi Vladykin
Cache.invoke(...) operates within a lock on a key, atomically, while "affinityCall(...)" is not atomic - it sends a computation to a node and can operate on multiple keys or start multiple transactions from the computation.

In your case, it seems that all you are doing is updating 1 key, so Cache.invoke(...) may be an option for you.
javadevmtl javadevmtl
Reply | Threaded
Open this post in threaded view
|

Re: Replace compute.affinityCall with cache.invoke

Yep. tried it works perfect! :)