cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Dejanovski <a...@thelastpickle.com>
Subject Re: execute is faster than execute_async?
Date Wed, 11 Dec 2019 12:44:25 GMT
Hi,

you can check this piece of documentation from Datastax:
https://docs.datastax.com/en/developer/python-driver/3.20/api/cassandra/cluster/#cassandra.cluster.Session.execute_async

The usual way of doing this is to send a bunch of execute_async() calls,
adding the returned futures in a list. Once the list reaches the chosen
threshold (usually we send around 100 queries and wait for them to finish
before moving on the the next ones), loop through the futures and call the
result() method to block until it completes.
Should look like this:

futures = []
for i in range(len(queries)):
    futures.append(session.execute_async(queries[i]))
    if len(futures) >= 100 or i == len(queries)-1:
        for future in futures:
            results = future.result() # will block until the query finishes
        futures = []  # empty the list


Haven't tested the code above but it should give you an idea on how this
can be implemented.
Sending hundreds/thousands of queries without waiting for a result will
DDoS the cluster, so you should always implement some throttling.

Cheers,

-----------------
Alexander Dejanovski
France
@alexanderdeja

Consultant
Apache Cassandra Consulting
http://www.thelastpickle.com


On Wed, Dec 11, 2019 at 10:42 AM Jordan West <jordanrw@gmail.com> wrote:

> I’m not very familiar with the python client unfortunately. If it helps:
> In Java, async would return futures and at the end of submitting each batch
> you would block on them by calling get.
>
> Jordan
>
> On Wed, Dec 11, 2019 at 1:37 AM lampahome <pahome.chen@mirlab.org> wrote:
>
>>
>>
>> Jordan West <jordanrw@gmail.com> 於 2019年12月11日 週三 下午4:34寫道:
>>
>>> Hi,
>>>
>>> Have you tried batching calls to execute_async with periodic blocking
>>> for the batch’s responses?
>>>
>>
>> Can you give me some keywords about calling execute_async batch?
>>
>> PS: I use python version.
>>
>

Mime
View raw message