This guide walks you through setting up and running your first Kafka performance tests.
git clone https://github.com/osodevops/kafka-performance-testing.git
cd kafka-performance-testing# Create virtual environment
python3 -m venv venv
# Activate it
source venv/bin/activate # Linux/macOS
# OR
venv\Scripts\activate # Windowspip install -r requirements.txtThis installs:
openpyxl- Excel report generationpandas- Data manipulationnumpy- Statistical calculations
ansible --version
# Should be 2.10 or higherIf not installed:
pip install ansibleFor quick local testing without a production Kafka cluster:
# Start 3-broker Kafka cluster
docker-compose up -d
# Wait for all services to be healthy
docker-compose ps
# View logs
docker-compose logs -fThis starts:
- Zookeeper - Kafka coordination (port 2181)
- 3 Kafka Brokers - Kafka cluster (ports 9092, 9093, 9094)
- Kafka UI - Web monitoring (http://localhost:8080)
- Perf Test Container - Test execution environment
# Enter the test container
docker exec -it kafka-perf-test bash
# Run a quick producer test
ansible-playbook -i examples/inventory/local \
playbooks/producer_baseline.yml
# Run full benchmark
ansible-playbook -i examples/inventory/local \
playbooks/full_benchmark.ymlResults are mounted to ./results/ on your host:
# On your host machine
ls results/reports/
open results/reports/kafka_perf_report_*.xlsx# Stop containers
docker-compose down
# Stop and remove volumes (clean slate)
docker-compose down -vEdit examples/inventory/dev/hosts.yml with your broker details:
all:
hosts:
kafka-broker-1:
ansible_host: your-broker-1.example.com
broker_id: 0
kafka-broker-2:
ansible_host: your-broker-2.example.com
broker_id: 1
kafka-broker-3:
ansible_host: your-broker-3.example.com
broker_id: 2
vars:
ansible_user: your-ssh-user
ansible_ssh_private_key_file: ~/.ssh/your-key
kafka_broker:
hosts:
- your-broker-1.example.com:9092
- your-broker-2.example.com:9092
- your-broker-3.example.com:9092For SSL/SASL clusters, add to examples/inventory/dev/group_vars/all/defaults.yml:
ssl_enabled: true
kafka_user: "your-username"
kafka_password: "your-password"Test SSH connectivity:
ansible -i examples/inventory/dev all -m pingTest Kafka connectivity:
ansible-playbook -i examples/inventory/dev \
playbooks/produce_consume.ymlansible-playbook -i examples/inventory/dev \
playbooks/produce_consume.ymlThis creates a test topic, produces 10 messages, consumes them, and cleans up.
ansible-playbook -i examples/inventory/dev \
playbooks/producer_baseline.ymlDefault quick profile runs with:
- 1 million records
- 1024 byte messages
- acks=1
- zstd compression
For comprehensive testing across all scenarios:
ansible-playbook -i examples/inventory/dev \
playbooks/full_benchmark.ymlLocated in results/raw_logs/:
producer_baseline_acks1_batch16384_linger10_zstd_size1024_20241216T120000.log
Contains raw kafka-producer-perf-test output:
1000000 records sent, 14637.645 records/sec (28.59 MB/sec),
3182.27 ms avg latency, 3613.00 ms max latency,
3289 ms 50th, 3467 ms 95th, 3568 ms 99th, 3603 ms 99.9th.
Located in results/parsed_data/:
{
"test_type": "producer",
"scenario": "baseline",
"configuration": {
"acks": "1",
"batch_size": "16384",
"linger_ms": "10"
},
"metrics": {
"throughput_mb": 28.59,
"avg_latency_ms": 3182.27,
"p99_ms": 3568
}
}Open results/reports/kafka_perf_report_*.xlsx:
- Summary Sheet - Start here for key findings and maximum throughput (MB/sec and msgs/sec)
- Producer Baseline - See throughput/latency charts
- Recommendations - Get actionable tuning suggestions
Edit examples/inventory/dev/group_vars/all/test_matrices.yml:
producer_test_matrix:
quick:
acks: ["1", "all"] # Add acks=all
batch_size: [16384, 64000] # Test larger batches
linger_ms: [10, 20] # Test higher linger# Only producer tests
ansible-playbook -i examples/inventory/dev \
playbooks/producer_baseline.yml
# Only message size analysis
ansible-playbook -i examples/inventory/dev \
playbooks/message_size_tests.ymlUse extra vars to override defaults:
ansible-playbook -i examples/inventory/dev \
playbooks/producer_baseline.yml \
-e "test_profile=baseline" \
-e "perf_num_records=5000000"- Review the Configuration Reference for all options
- Read Test Scenarios to understand each test type
- Check Troubleshooting if you encounter issues
- Explore the Architecture to understand the system
# Quick producer test
ansible-playbook -i examples/inventory/dev playbooks/producer_baseline.yml
# Full benchmark
ansible-playbook -i examples/inventory/dev playbooks/full_benchmark.yml
# Dry run (check mode)
ansible-playbook -i examples/inventory/dev playbooks/producer_baseline.yml --check
# Verbose output
ansible-playbook -i examples/inventory/dev playbooks/producer_baseline.yml -v
# Only parse logs (skip tests)
ansible-playbook -i examples/inventory/dev playbooks/full_benchmark.yml --tags parse,reportresults/
├── raw_logs/ # Test output logs
├── parsed_data/ # JSON metrics
└── reports/ # Excel reports