Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/23/2020

Reading time:N/A min

DataStax-Examples/concurrent-requests-python

by DataStax-Examples

This example shows how execute multiple concurrent requests asynchronously with Apache Cassandra™ using the Python DataStax Driver.Contributor(s): Alan Boudreault - derived from hereObjectivesHow to limit async concurrent requests using the DataStax Python DriverProject Layoutexecute_async_with_queue.py: uses a Queue to cap the number of simultaneous requests triggered by the Python driver while executing asynchronously.How this worksAfter running the docker command, there will be a running instance of the DataStax Distribution of Apache Cassandra.The Python program executes requests in a non-blocking, asynchronous manner while limiting the number of in-flight requests.Setup & RunningPrerequisitesDocker installed and started: https://docs.docker.com/v17.09/engine/installation/SetupMake sure Cassandra Python Driver is installedpip install cassandra-driverClone this repositorygit clone https://github.com/DataStax-Examples/concurrent-requests-python.gitGo to the directorycd concurrent-requests-pythonStart the DDAC docker containerdocker run -e DS_LICENSE=accept --name ddac -p 127.0.0.1:9042:9042 -d datastax/ddac RunningRun the Python programpython execute_async_with_queue.pyExpected OutputFinished executing 10000 queries with a concurrency level of 32 in 2.61 seconds.

Illustration Image

This example shows how execute multiple concurrent requests asynchronously with Apache Cassandra™ using the Python DataStax Driver.

Contributor(s): Alan Boudreault - derived from here

Objectives

  • How to limit async concurrent requests using the DataStax Python Driver

Project Layout

  • execute_async_with_queue.py: uses a Queue to cap the number of simultaneous requests triggered by the Python driver while executing asynchronously.

How this works

After running the docker command, there will be a running instance of the DataStax Distribution of Apache Cassandra.

The Python program executes requests in a non-blocking, asynchronous manner while limiting the number of in-flight requests.

Setup & Running

Prerequisites

Setup

Make sure Cassandra Python Driver is installed

pip install cassandra-driver

Clone this repository

git clone https://github.com/DataStax-Examples/concurrent-requests-python.git

Go to the directory

cd concurrent-requests-python

Start the DDAC docker container

docker run -e DS_LICENSE=accept --name ddac -p 127.0.0.1:9042:9042 -d datastax/ddac 

Running

Run the Python program

python execute_async_with_queue.py

Expected Output

Finished executing 10000 queries with a concurrency level of 32 in 2.61 seconds.

Related Articles

node
python
astra

GitHub - Anant/Cassandra.Api: Open Source Application for DataStax Astra

Anant

3/7/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

examples