Async cassandra queries










1















I've been trying to update an app to enhance performance, it uses Datastax Cassandra Java Driver for DAL services.



Now, I need to convert sync queries to async queries, I didn't find satisfactory answers to my doubts (at least not on the web pages I visited).



Could anybody please answer the below queries or refer to a link where I could get an answer.



1> What are the possible problematic scenarios I need to worry about before changing synced executes to ansync execs?



2> How will reads and writes behave, can I change one of them without worrying about any issues?



Thanks in advance!










share|improve this question
























  • Asyn queries references: 1) datastax.com/dev/blog/java-driver-async-queries 2) docs.datastax.com/en/developer/java-driver/3.6/manual/async

    – abpan
    Nov 12 '18 at 14:16
















1















I've been trying to update an app to enhance performance, it uses Datastax Cassandra Java Driver for DAL services.



Now, I need to convert sync queries to async queries, I didn't find satisfactory answers to my doubts (at least not on the web pages I visited).



Could anybody please answer the below queries or refer to a link where I could get an answer.



1> What are the possible problematic scenarios I need to worry about before changing synced executes to ansync execs?



2> How will reads and writes behave, can I change one of them without worrying about any issues?



Thanks in advance!










share|improve this question
























  • Asyn queries references: 1) datastax.com/dev/blog/java-driver-async-queries 2) docs.datastax.com/en/developer/java-driver/3.6/manual/async

    – abpan
    Nov 12 '18 at 14:16














1












1








1








I've been trying to update an app to enhance performance, it uses Datastax Cassandra Java Driver for DAL services.



Now, I need to convert sync queries to async queries, I didn't find satisfactory answers to my doubts (at least not on the web pages I visited).



Could anybody please answer the below queries or refer to a link where I could get an answer.



1> What are the possible problematic scenarios I need to worry about before changing synced executes to ansync execs?



2> How will reads and writes behave, can I change one of them without worrying about any issues?



Thanks in advance!










share|improve this question
















I've been trying to update an app to enhance performance, it uses Datastax Cassandra Java Driver for DAL services.



Now, I need to convert sync queries to async queries, I didn't find satisfactory answers to my doubts (at least not on the web pages I visited).



Could anybody please answer the below queries or refer to a link where I could get an answer.



1> What are the possible problematic scenarios I need to worry about before changing synced executes to ansync execs?



2> How will reads and writes behave, can I change one of them without worrying about any issues?



Thanks in advance!







asynchronous cassandra cassandra-2.0 datastax-java-driver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 18:59









Alex Ott

27.3k35072




27.3k35072










asked Nov 12 '18 at 8:50









Kumar KavishKumar Kavish

123




123












  • Asyn queries references: 1) datastax.com/dev/blog/java-driver-async-queries 2) docs.datastax.com/en/developer/java-driver/3.6/manual/async

    – abpan
    Nov 12 '18 at 14:16


















  • Asyn queries references: 1) datastax.com/dev/blog/java-driver-async-queries 2) docs.datastax.com/en/developer/java-driver/3.6/manual/async

    – abpan
    Nov 12 '18 at 14:16

















Asyn queries references: 1) datastax.com/dev/blog/java-driver-async-queries 2) docs.datastax.com/en/developer/java-driver/3.6/manual/async

– abpan
Nov 12 '18 at 14:16






Asyn queries references: 1) datastax.com/dev/blog/java-driver-async-queries 2) docs.datastax.com/en/developer/java-driver/3.6/manual/async

– abpan
Nov 12 '18 at 14:16













1 Answer
1






active

oldest

votes


















1














There are several things that you need to think about:



  • You need to rate limit your code - by default it's only 1024 request per connection, so you may need to increase this number. But even with increased number of request per connection it's easy to overload Cassandra, so you still need to control it, with something like this;

  • You need correctly handle errors - you may need to add error handler to promise that is returned, and react correspondingly;

  • You need correctly create statements - for example, don't reuse the same BoundStatement as it's not thread safe;

  • don't re-use same List/Set/Map instances that you pass as parameters, etc.





share|improve this answer























  • Thanks Alex, one more thing, how exactly does pairing batch statements with executeAsync work, given that batches maintain atomicity. Can I combine them to get a better performance without losing atomicity?

    – Kumar Kavish
    Nov 20 '18 at 9:04











  • there are different types of batches - you can batch for multiple tables, you can batch for same table, etc. If you batch for same partition inside table, then it's much faster than sending the same queries multiple times. But otherwise, use of batches with executeAsync is the same as with execute...

    – Alex Ott
    Nov 20 '18 at 9:11











  • great! made it perfectly clear, well in my case the batch is for multiple tables, so I think using executeAsync is useless.

    – Kumar Kavish
    Nov 20 '18 at 9:38











  • Why, it's still useful, as you can still parallelize execution, without adding more threads. But you really need to think about use of batches - they are quite expensive, and should be used only in limited amount of cases

    – Alex Ott
    Nov 20 '18 at 9:40











  • Using batches to ensure the atomicity of the transaction. The initial code that I wrote was to process the batch in async fashion. I have multiple transactions, each with a set of upserts. So, rather than executing batch for each of them in a synced manner, I am trying to use async with each batch to get better performance. Makes sense, right?

    – Kumar Kavish
    Nov 20 '18 at 9:49











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258590%2fasync-cassandra-queries%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














There are several things that you need to think about:



  • You need to rate limit your code - by default it's only 1024 request per connection, so you may need to increase this number. But even with increased number of request per connection it's easy to overload Cassandra, so you still need to control it, with something like this;

  • You need correctly handle errors - you may need to add error handler to promise that is returned, and react correspondingly;

  • You need correctly create statements - for example, don't reuse the same BoundStatement as it's not thread safe;

  • don't re-use same List/Set/Map instances that you pass as parameters, etc.





share|improve this answer























  • Thanks Alex, one more thing, how exactly does pairing batch statements with executeAsync work, given that batches maintain atomicity. Can I combine them to get a better performance without losing atomicity?

    – Kumar Kavish
    Nov 20 '18 at 9:04











  • there are different types of batches - you can batch for multiple tables, you can batch for same table, etc. If you batch for same partition inside table, then it's much faster than sending the same queries multiple times. But otherwise, use of batches with executeAsync is the same as with execute...

    – Alex Ott
    Nov 20 '18 at 9:11











  • great! made it perfectly clear, well in my case the batch is for multiple tables, so I think using executeAsync is useless.

    – Kumar Kavish
    Nov 20 '18 at 9:38











  • Why, it's still useful, as you can still parallelize execution, without adding more threads. But you really need to think about use of batches - they are quite expensive, and should be used only in limited amount of cases

    – Alex Ott
    Nov 20 '18 at 9:40











  • Using batches to ensure the atomicity of the transaction. The initial code that I wrote was to process the batch in async fashion. I have multiple transactions, each with a set of upserts. So, rather than executing batch for each of them in a synced manner, I am trying to use async with each batch to get better performance. Makes sense, right?

    – Kumar Kavish
    Nov 20 '18 at 9:49
















1














There are several things that you need to think about:



  • You need to rate limit your code - by default it's only 1024 request per connection, so you may need to increase this number. But even with increased number of request per connection it's easy to overload Cassandra, so you still need to control it, with something like this;

  • You need correctly handle errors - you may need to add error handler to promise that is returned, and react correspondingly;

  • You need correctly create statements - for example, don't reuse the same BoundStatement as it's not thread safe;

  • don't re-use same List/Set/Map instances that you pass as parameters, etc.





share|improve this answer























  • Thanks Alex, one more thing, how exactly does pairing batch statements with executeAsync work, given that batches maintain atomicity. Can I combine them to get a better performance without losing atomicity?

    – Kumar Kavish
    Nov 20 '18 at 9:04











  • there are different types of batches - you can batch for multiple tables, you can batch for same table, etc. If you batch for same partition inside table, then it's much faster than sending the same queries multiple times. But otherwise, use of batches with executeAsync is the same as with execute...

    – Alex Ott
    Nov 20 '18 at 9:11











  • great! made it perfectly clear, well in my case the batch is for multiple tables, so I think using executeAsync is useless.

    – Kumar Kavish
    Nov 20 '18 at 9:38











  • Why, it's still useful, as you can still parallelize execution, without adding more threads. But you really need to think about use of batches - they are quite expensive, and should be used only in limited amount of cases

    – Alex Ott
    Nov 20 '18 at 9:40











  • Using batches to ensure the atomicity of the transaction. The initial code that I wrote was to process the batch in async fashion. I have multiple transactions, each with a set of upserts. So, rather than executing batch for each of them in a synced manner, I am trying to use async with each batch to get better performance. Makes sense, right?

    – Kumar Kavish
    Nov 20 '18 at 9:49














1












1








1







There are several things that you need to think about:



  • You need to rate limit your code - by default it's only 1024 request per connection, so you may need to increase this number. But even with increased number of request per connection it's easy to overload Cassandra, so you still need to control it, with something like this;

  • You need correctly handle errors - you may need to add error handler to promise that is returned, and react correspondingly;

  • You need correctly create statements - for example, don't reuse the same BoundStatement as it's not thread safe;

  • don't re-use same List/Set/Map instances that you pass as parameters, etc.





share|improve this answer













There are several things that you need to think about:



  • You need to rate limit your code - by default it's only 1024 request per connection, so you may need to increase this number. But even with increased number of request per connection it's easy to overload Cassandra, so you still need to control it, with something like this;

  • You need correctly handle errors - you may need to add error handler to promise that is returned, and react correspondingly;

  • You need correctly create statements - for example, don't reuse the same BoundStatement as it's not thread safe;

  • don't re-use same List/Set/Map instances that you pass as parameters, etc.






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 10:14









Alex OttAlex Ott

27.3k35072




27.3k35072












  • Thanks Alex, one more thing, how exactly does pairing batch statements with executeAsync work, given that batches maintain atomicity. Can I combine them to get a better performance without losing atomicity?

    – Kumar Kavish
    Nov 20 '18 at 9:04











  • there are different types of batches - you can batch for multiple tables, you can batch for same table, etc. If you batch for same partition inside table, then it's much faster than sending the same queries multiple times. But otherwise, use of batches with executeAsync is the same as with execute...

    – Alex Ott
    Nov 20 '18 at 9:11











  • great! made it perfectly clear, well in my case the batch is for multiple tables, so I think using executeAsync is useless.

    – Kumar Kavish
    Nov 20 '18 at 9:38











  • Why, it's still useful, as you can still parallelize execution, without adding more threads. But you really need to think about use of batches - they are quite expensive, and should be used only in limited amount of cases

    – Alex Ott
    Nov 20 '18 at 9:40











  • Using batches to ensure the atomicity of the transaction. The initial code that I wrote was to process the batch in async fashion. I have multiple transactions, each with a set of upserts. So, rather than executing batch for each of them in a synced manner, I am trying to use async with each batch to get better performance. Makes sense, right?

    – Kumar Kavish
    Nov 20 '18 at 9:49


















  • Thanks Alex, one more thing, how exactly does pairing batch statements with executeAsync work, given that batches maintain atomicity. Can I combine them to get a better performance without losing atomicity?

    – Kumar Kavish
    Nov 20 '18 at 9:04











  • there are different types of batches - you can batch for multiple tables, you can batch for same table, etc. If you batch for same partition inside table, then it's much faster than sending the same queries multiple times. But otherwise, use of batches with executeAsync is the same as with execute...

    – Alex Ott
    Nov 20 '18 at 9:11











  • great! made it perfectly clear, well in my case the batch is for multiple tables, so I think using executeAsync is useless.

    – Kumar Kavish
    Nov 20 '18 at 9:38











  • Why, it's still useful, as you can still parallelize execution, without adding more threads. But you really need to think about use of batches - they are quite expensive, and should be used only in limited amount of cases

    – Alex Ott
    Nov 20 '18 at 9:40











  • Using batches to ensure the atomicity of the transaction. The initial code that I wrote was to process the batch in async fashion. I have multiple transactions, each with a set of upserts. So, rather than executing batch for each of them in a synced manner, I am trying to use async with each batch to get better performance. Makes sense, right?

    – Kumar Kavish
    Nov 20 '18 at 9:49

















Thanks Alex, one more thing, how exactly does pairing batch statements with executeAsync work, given that batches maintain atomicity. Can I combine them to get a better performance without losing atomicity?

– Kumar Kavish
Nov 20 '18 at 9:04





Thanks Alex, one more thing, how exactly does pairing batch statements with executeAsync work, given that batches maintain atomicity. Can I combine them to get a better performance without losing atomicity?

– Kumar Kavish
Nov 20 '18 at 9:04













there are different types of batches - you can batch for multiple tables, you can batch for same table, etc. If you batch for same partition inside table, then it's much faster than sending the same queries multiple times. But otherwise, use of batches with executeAsync is the same as with execute...

– Alex Ott
Nov 20 '18 at 9:11





there are different types of batches - you can batch for multiple tables, you can batch for same table, etc. If you batch for same partition inside table, then it's much faster than sending the same queries multiple times. But otherwise, use of batches with executeAsync is the same as with execute...

– Alex Ott
Nov 20 '18 at 9:11













great! made it perfectly clear, well in my case the batch is for multiple tables, so I think using executeAsync is useless.

– Kumar Kavish
Nov 20 '18 at 9:38





great! made it perfectly clear, well in my case the batch is for multiple tables, so I think using executeAsync is useless.

– Kumar Kavish
Nov 20 '18 at 9:38













Why, it's still useful, as you can still parallelize execution, without adding more threads. But you really need to think about use of batches - they are quite expensive, and should be used only in limited amount of cases

– Alex Ott
Nov 20 '18 at 9:40





Why, it's still useful, as you can still parallelize execution, without adding more threads. But you really need to think about use of batches - they are quite expensive, and should be used only in limited amount of cases

– Alex Ott
Nov 20 '18 at 9:40













Using batches to ensure the atomicity of the transaction. The initial code that I wrote was to process the batch in async fashion. I have multiple transactions, each with a set of upserts. So, rather than executing batch for each of them in a synced manner, I am trying to use async with each batch to get better performance. Makes sense, right?

– Kumar Kavish
Nov 20 '18 at 9:49






Using batches to ensure the atomicity of the transaction. The initial code that I wrote was to process the batch in async fashion. I have multiple transactions, each with a set of upserts. So, rather than executing batch for each of them in a synced manner, I am trying to use async with each batch to get better performance. Makes sense, right?

– Kumar Kavish
Nov 20 '18 at 9:49


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258590%2fasync-cassandra-queries%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo