You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by M Mansur Ashraf <ma...@gmail.com> on 2018/02/05 22:20:38 UTC
Design help implementing custom counters on ignite
Hey guys,
I am new to Ignite and trying to implement a custom counter. I read the
document and it seems like I can implement my counter in three different
ways so need some help figuring out which approach to take.
//business logic in pseudo code
Ignite ignite = Ignition.ignite();
IgniteTransactions transactions = ignite.transactions();
try (Transaction tx = transactions.txStart()) {
Account account = cache.get(accNbr);
long amount =account.getAmount()
account.updatedAmount(amount+10)
cache.put(accNbr,account);
tx.commit();
}
// end code
As far as I can tell, I can run this code
1) on the client side (maybe slow due to transaction?)
2) I can run it as IgniteCompute.affinityCall(...) on the grid itself. (I
am
assuming I can start tx inside affinityCall)
3) Run this code as a Cluster Singleton behind a service
Please note that there could be multiple clients on different machines,
trying to update the same account so transaction locking is important. I am
leaning toward using affinityCall to implement this but was wondering
whether this is the correct approach?
Thanks
Re: Design help implementing custom counters on ignite
Posted by Michael Cherkasov <mi...@gmail.com>.
Hi Mansoor,
in general, there're two approaches:
1. get data to a client, update and send it back
2. send code to data and make the update there
Both can work, which one is faster depends on your case, it depends on data
model size, backup count, your network speed.
So this is something that you should benchmark:)
Thanks,
Mike.
2018-02-05 14:20 GMT-08:00 M Mansur Ashraf <ma...@gmail.com>:
> Hey guys,
>
> I am new to Ignite and trying to implement a custom counter. I read the
> document and it seems like I can implement my counter in three different
> ways so need some help figuring out which approach to take.
>
> //business logic in pseudo code
>
> Ignite ignite = Ignition.ignite();
> IgniteTransactions transactions = ignite.transactions();
> try (Transaction tx = transactions.txStart()) {
> Account account = cache.get(accNbr);
> long amount =account.getAmount()
> account.updatedAmount(amount+10)
> cache.put(accNbr,account);
> tx.commit();
> }
>
> // end code
>
> As far as I can tell, I can run this code
>
> 1) on the client side (maybe slow due to transaction?)
> 2) I can run it as IgniteCompute.affinityCall(...) on the grid itself. (I
> am
> assuming I can start tx inside affinityCall)
> 3) Run this code as a Cluster Singleton behind a service
>
> Please note that there could be multiple clients on different machines,
> trying to update the same account so transaction locking is important. I
> am
> leaning toward using affinityCall to implement this but was wondering
> whether this is the correct approach?
>
> Thanks
>
Re: Design help implementing custom counters on ignite
Posted by vkulichenko <va...@gmail.com>.
I would also recommend to take a look at EntryProcessor [1]. It allows to do
co-located atomic updates, so it doesn't require transaction and reduces the
amount of data transferred across network, so it should give best
performance results.
[1] https://apacheignite.readme.io/docs/jcache#entryprocessor
-Val
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/