This example shows how execute multiple concurrent requests asynchronously with Apache Cassandra™ using the Python DataStax Driver.
- How to limit async concurrent requests using the DataStax Python Driver
- 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
- Docker installed and started: https://docs.docker.com/v17.09/engine/installation/
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
Start the DDAC docker container
docker run -e DS_LICENSE=accept --name ddac -p 127.0.0.1:9042:9042 -d datastax/ddac
Run the Python program
Finished executing 10000 queries with a concurrency level of 32 in 2.61 seconds.