A comprehensive performance testing framework to evaluate the async-python-cassandra client against the standard Python Cassandra driver.
This framework provides:
- Two identical FastAPI applications (async and sync implementations)
- Performance testing endpoints
- Real-time monitoring with Prometheus and Grafana
- Load testing capabilities
- Interactive web UI for testing and visualization
- Docker and Docker Compose
- Python 3.12+ (for local development)
- 8GB+ RAM recommended
# Clone the repository
git clone <repository-url>
cd async-python-cassandra-client-examples
# Copy environment variables
cp .env.example .env
# Start all services
docker-compose up -d
# Wait for services to be healthy
docker-compose ps
# View logs
docker-compose logs -f
# Set your Cassandra cluster details
export CASSANDRA_HOSTS=cassandra1.example.com,cassandra2.example.com
export CASSANDRA_USERNAME=your_username
export CASSANDRA_PASSWORD=your_password
# Use the external compose file
docker-compose -f docker-compose.external.yml up -d
- Web UI: http://localhost:3001 (provides access to all services)
- All other services run on internal network and are accessible through the Web UI
POST /api/v1/users
- Create userGET /api/v1/users/{id}
- Get user by IDGET /api/v1/users
- List users with paginationPUT /api/v1/users/{id}
- Update userDELETE /api/v1/users/{id}
- Delete userPOST /api/v1/documents
- Create documentGET /api/v1/documents/{id}
- Get document
GET /api/v1/stream/sensor-data
- Stream sensor dataGET /api/v1/stream/large-dataset/{size}
- Stream large datasetGET /api/v1/stream/documents
- Stream documents
Performance testing should be done using external load testing tools that generate concurrent requests from outside the application. This provides accurate measurements of how the applications handle real-world load.
# Run automated comparison tests
cd load-testing
python compare.py
This will run identical workloads against both applications and generate a comparison report with visualizations.
# Install dependencies
pip install -r load-testing/requirements.txt
# Run Locust tests
cd load-testing
locust -f locustfile.py --host http://localhost:3001
# Run k6 tests (requires k6 installation)
k6 run k6-script.js --env BASE_URL=http://localhost:3001
# Run comprehensive test suite
./run-tests.sh
- Always test from external clients: Never simulate load from within the application itself
- Test both applications identically: Use the same workload patterns for fair comparison
- Monitor resource usage: Watch CPU, memory, and connection pool metrics during tests
- Test different scenarios:
- Light load (baseline performance)
- Normal load (expected traffic)
- Heavy load (peak traffic)
- Stress test (beyond capacity)
- Navigate to http://localhost:3001 and click on Grafana
- Login with admin/admin
- Import provided dashboards from
monitoring/grafana/dashboards/
- Request rate and latency
- Cassandra query performance
- Connection pool statistics
- Resource utilization
- Error rates
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install async app dependencies
cd apps/async-app
pip install -r requirements.txt
# Run async app locally
python -m app.main
# In another terminal, run sync app
cd apps/sync-app
pip install -r requirements.txt
python -m app.main
# Unit tests
pytest apps/async-app/tests
pytest apps/sync-app/tests
# Integration tests
docker-compose up -d
pytest integration-tests/
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Web UI │ │ Grafana │ │ Prometheus │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
├───────────────────┴────────────────────┤
│ │
┌──────▼──────┐ ┌──────────────┐ ┌──────▼──────┐
│ Async App │ │ │ │ Sync App │
│ (FastAPI) │ │ Cassandra │ │ (FastAPI) │
│async-client │────▶│ Cluster │◀───│ sync-driver │
└─────────────┘ └──────────────┘ └─────────────┘
Key environment variables:
# Cassandra settings
CASSANDRA_HOSTS=localhost
CASSANDRA_PORT=9042
CASSANDRA_KEYSPACE=perftest
CASSANDRA_USERNAME=
CASSANDRA_PASSWORD=
# Performance settings
MAX_CONNECTIONS=100
CONNECTION_TIMEOUT=10
REQUEST_TIMEOUT=30
BATCH_SIZE=100
STREAM_BUFFER_SIZE=1000
# Application settings
APP_PORT=8000
WORKERS=4
LOG_LEVEL=INFO
- Cassandra not starting: Increase Docker memory allocation
- Connection refused: Wait for Cassandra health check to pass
- Metrics not showing: Check Prometheus targets through the Web UI
# Check service health
docker-compose ps
# View logs
docker-compose logs -f cassandra
docker-compose logs -f async-app
# Access Cassandra shell
docker-compose exec cassandra cqlsh
# Restart a service
docker-compose restart async-app
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
MIT License - see LICENSE file for details