cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charulata Sharma (charshar)" <>
Subject Re: Async queries
Date Tue, 03 Oct 2017 04:40:00 GMT
Thanks Andy for the detailed explanation. I have added the callback feature and am going to
test if this helps.


From: Andy Tolbert <>
Reply-To: "" <>
Date: Monday, October 2, 2017 at 5:48 PM
To: "" <>
Subject: Re: Async queries

Hi Charu,

Since the driver uses Guava futures, you can use some of the methods in Futures<>
to add listeners, callbacks and transformers that are invoked when the future completes without
blocking the calling thread like getUninterruptibly does.  For example, the following registers
a callback whose onSuccess or onFailure method is called based on the success of the query.

Futures.addCallback(future, new FutureCallback<ResultSet>() {
    public void onSuccess(ResultSet result) {
        // process result

    public void onFailure(Throwable t) {
        // log exception

You can read more about using the driver's async features here<>.

Since executeAsync does not block, you'll want to be careful of is not submitting too many
requests at a time as this can degrade performance and may explain what you are observing.
 One simple (although somewhat crude) way of handling this is to use a Semaphore with a fixed
number of permits.  You would acquire a Semaphore permit before you execute a query, and then
release a permit in a callback on completion of the request.  This would cause your calling
thread to block whenever you run out of permits, and then continue when a query completes
and releases a permit.

The upcoming version (4.0) of the java driver uses CompletionStage/CompletableFuture (java
8 futures), although we'll probably provide a guava extension as well for those who still
want to use ListenableFuture.


On Mon, Oct 2, 2017 at 6:44 PM Charulata Sharma (charshar) <<>>
Hi ,

We are observing some performance issues when executing a large number of read/write queries.
We use executeAsync query for most of our read and write requests and then future.getUninterruptibly()
methods before returning to the client application.

Code snippet is:  (In the bind portion we have some GSON object conversions.

     List<ResultSetFuture> futures = new ArrayList<>();

      BoundStatement bind ;
      For(loop condition) {
        bind =PreparedStatement.bind(….) //The PreparedStatement is prepared outside the
       resultSetFuture = SESSION.executeAsync(bind);
     futures.add(resultSetFu ture);

for(ResultSetFuture future: futures){

Reading through the documents , I found that although the queries are executed in an async
fashion, the future. getUninterruptibly(), is a blocking call.
I am trying to implement a callable future, but wanted to know from the community if there
is any better way of doing this and if changing to callable future will help.

View raw message