Skip to content

Commit ae1d06f

Browse files
committed
Add AES, KMS, MOST RECENT PROVIDER
1 parent f9c4b1b commit ae1d06f

17 files changed

+7610
-554
lines changed
Lines changed: 85 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,239 +1,142 @@
1-
# AWS Database Encryption SDK - DynamoDB Performance Tests
1+
# Python Performance Tests: DDBEC v3 vs DB-ESDK v4
22

3-
This directory contains comprehensive performance tests comparing the Legacy DynamoDB Encryption Client Python v3 (DDBEC v3) against the AWS Database Encryption SDK Python v4 (DB-ESDK v4).
3+
This directory contains comprehensive performance benchmarks comparing the **Legacy DynamoDB Encryption Client Python v3** (DDBEC v3) against the **AWS Database Encryption SDK Python v4** (DB-ESDK v4).
44

55
## Overview
66

7-
The performance tests benchmark encryption and decryption operations across:
7+
The performance tests benchmark encryption and decryption operations using pytest-benchmark across multiple data types and encryption providers/keyrings.
88

9-
### DDBEC v3 Providers
9+
### Libraries Under Test
10+
11+
**DDBEC v3 Providers:**
1012
- AES Key Provider
1113
- AWS KMS Key Provider
1214
- Most Recent Key Provider
1315

14-
### DB-ESDK v4 Keyrings
16+
**DB-ESDK v4 Keyrings:**
1517
- Raw AES Keyring
1618
- AWS KMS Keyring
17-
- Hierarchy Keyring (simplified for testing)
18-
19-
### Test Data Categories
20-
- **Single Attribute**: Simple string attribute
21-
- **Nested Attributes**: Complex nested JSON structure
22-
- **Flat Attributes**: Many top-level attributes
23-
24-
## Prerequisites
19+
- Hierarchy Keyring
2520

26-
1. **Python 3.8+** installed
27-
2. **AWS credentials** configured (for KMS tests)
28-
3. **AWS KMS key** with appropriate permissions
21+
### Test Data Types
22+
- **single_attribute**: Simple string data
23+
- **nested_attributes**: Complex nested JSON structures
24+
- **flat_attributes**: Multiple top-level attributes
2925

30-
## Installation
26+
## Quick Start
3127

32-
1. Install Poetry (if not already installed):
33-
```bash
34-
curl -sSL https://install.python-poetry.org | python3 -
35-
```
28+
### Prerequisites
29+
- Python 3.11+
30+
- Poetry installed
31+
- AWS credentials configured
32+
- Access to AWS KMS key: `arn:aws:kms:us-west-2:370957321024:key/9d989aa2-2f9c-438c-a745-cc57d3ad0126`
3633

37-
2. Install dependencies:
34+
### Installation
3835
```bash
39-
poetry install --with test
36+
cd PerfTest/runtimes/python/DynamoDbEncryption
37+
poetry install
4038
```
4139

42-
## Running the Tests
43-
44-
### Using Tox (Recommended)
45-
46-
Run all performance tests:
40+
### Run All Benchmarks
4741
```bash
48-
# Run all tests
49-
tox -e py311-all
50-
51-
# Run only v3 tests
52-
tox -e py311-v3
53-
54-
# Run only v4 tests
55-
tox -e py311-v4
56-
57-
# Run the benchmark script
5842
tox -e run-benchmarks
59-
```
6043

61-
### Using Poetry Directly
44+
# Or
45+
python run_benchmarks.py
6246

63-
```bash
64-
# Run all tests
65-
poetry run pytest src/ --benchmark-only
66-
67-
# Run the benchmark script
47+
# Or using poetry
6848
poetry run python run_benchmarks.py
6949
```
7050

71-
### Command Line Options
51+
## Usage Examples
7252

53+
### Basic Commands
7354
```bash
74-
poetry run python run_benchmarks.py [OPTIONS]
75-
76-
Options:
77-
--version {v3,v4,all} Which version to benchmark (default: all)
78-
--test PATTERN Run specific test pattern (e.g., 'aes' or 'encrypt')
79-
--output-dir DIR Directory to save results (default: benchmark_results)
80-
--no-save Don't save results to files
81-
--pytest-args ARGS Additional pytest arguments
82-
```
55+
# Run all tests with comparison report
56+
python run_benchmarks.py
8357

84-
### Examples with Tox
58+
# Test only DDBEC v3
59+
python run_benchmarks.py --version v3
8560

86-
```bash
87-
# Run with different Python versions
88-
tox -e py311-all
89-
tox -e py312-all
90-
tox -e py313-all
61+
# Test only DB-ESDK v4
62+
python run_benchmarks.py --version v4
9163

92-
# Run linting
93-
tox -e lint
64+
# Test specific provider (AES, KMS, etc.)
65+
python run_benchmarks.py --test kms
9466

95-
# Format code
96-
tox -e format
67+
# Test only encryption operations
68+
python run_benchmarks.py --test encrypt
9769
```
9870

99-
### Examples with Poetry
100-
101-
1. **Run only v3 tests:**
102-
```bash
103-
poetry run python run_benchmarks.py --version v3
104-
```
105-
106-
2. **Run only AES-based tests:**
107-
```bash
108-
poetry run python run_benchmarks.py --test aes
109-
```
71+
### Advanced Options
72+
```bash
73+
# Don't save files, only show console output
74+
python run_benchmarks.py --no-save
11075

111-
3. **Run only encryption tests:**
112-
```bash
113-
poetry run python run_benchmarks.py --test encrypt
114-
```
76+
# Save to custom directory
77+
python run_benchmarks.py --output-dir my_results
11578

116-
4. **Run with custom pytest options:**
117-
```bash
118-
poetry run python run_benchmarks.py --pytest-args "--benchmark-rounds=20"
119-
```
79+
# Pass additional pytest arguments
80+
python run_benchmarks.py --pytest-args "--benchmark-rounds=10"
81+
```
12082

12183
### Direct pytest Usage
122-
123-
You can also run pytest directly with more control:
124-
12584
```bash
126-
# Run all tests
127-
poetry run pytest -v --benchmark-only
128-
129-
# Run only v3 tests
130-
poetry run pytest -v --benchmark-only -m v3
85+
# Run with pytest directly
86+
poetry run pytest src/ --benchmark-only -v
13187

132-
# Run only v4 tests
133-
poetry run pytest -v --benchmark-only -m v4
88+
# Run specific test file
89+
poetry run pytest src/v3/aes_key_provider_test.py --benchmark-only -v
13490

135-
# Run specific provider tests
136-
poetry run pytest -v --benchmark-only -k "aes"
137-
poetry run pytest -v --benchmark-only -k "kms"
138-
139-
# Run with custom benchmark options
140-
poetry run pytest -v --benchmark-only --benchmark-columns=min,max,mean,ops
91+
# Run single test function
92+
poetry run pytest src/v4/raw_aes_keyring_test.py::test_encrypt_performance[single_attribute] --benchmark-only -v
14193
```
14294

14395
## Output
14496

145-
The benchmark script generates multiple output formats:
146-
147-
1. **Console Output**: Immediate results with comparison table
148-
2. **CSV Files**: Raw results and comparison data
149-
3. **JSON Files**: Detailed benchmark data
150-
4. **HTML Report**: Visual comparison report
151-
152-
Results are saved in the `benchmark_results/` directory with timestamps.
153-
154-
## Understanding the Results
155-
156-
### Performance Metrics
157-
- **Mean**: Average time per operation
158-
- **Min/Max**: Best and worst case times
159-
- **Ops/sec**: Operations per second
160-
- **StdDev**: Standard deviation of measurements
161-
162-
### Comparison Report
163-
- **Negative percentages**: v4 is faster than v3
164-
- **Positive percentages**: v4 is slower than v3
165-
166-
### Size Comparison
167-
For encryption operations, the report includes:
168-
- Original item size
169-
- Encrypted item size
170-
- Size increase ratio
171-
172-
## Test Structure
97+
The benchmark script generates:
17398

99+
### Console Report
174100
```
175-
src/
176-
├── __init__.py
177-
├── test_constants.py # Shared constants
178-
├── v3/ # DDBEC v3 tests
179-
│ ├── __init__.py
180-
│ ├── test_base.py # Base class for v3 tests
181-
│ ├── aes_key_provider_test.py
182-
│ ├── aws_kms_key_provider_test.py
183-
│ └── most_recent_key_provider_test.py
184-
└── v4/ # DB-ESDK v4 tests
185-
├── __init__.py
186-
├── test_base.py # Base class for v4 tests
187-
├── raw_aes_keyring_test.py
188-
├── aws_kms_keyring_test.py
189-
└── hierarchy_keyring_test.py
190-
191-
resources/ # Test data files
192-
├── single_attribute.json
193-
├── nested_attributes.json
194-
└── flat_attributes.json
101+
PERFORMANCE COMPARISON: DDBEC v3 vs DB-ESDK v4
102+
===============================================
103+
104+
Operation | Data Type | Provider | DDBEC(v3) Mean (ms) | DB ESDK(v4) Mean (ms) | Difference (ms) | DB ESDK(v4) vs DDBEC(v3) (%)
195105
```
196106

197-
## Environment Variables
107+
### Generated Files
108+
- `raw_results_TIMESTAMP.csv/json` - Detailed benchmark data
109+
- `comparison_TIMESTAMP.csv/json` - Side-by-side comparison
110+
- `report_TIMESTAMP.html` - Visual HTML report
198111

199-
- `AWS_REGION`: AWS region for KMS operations (default: us-west-2)
200-
- `AWS_PROFILE`: AWS profile to use for credentials
112+
All files saved to `benchmark_results/` directory.
201113

202-
## Troubleshooting
114+
## Understanding Results
203115

204-
### AWS Credentials
205-
Ensure AWS credentials are properly configured:
206-
```bash
207-
aws configure list
208-
```
116+
### Performance Metrics
117+
- **Mean (ms)**: Average execution time per operation in milliseconds
118+
- **Difference (ms)**: Time difference (DB-ESDK v4 - DDBEC v3) in milliseconds
119+
- **Percentage**: Performance change (negative = v4 faster, positive = v4 slower)
209120

210-
### KMS Key Access
211-
Verify access to the KMS key:
212-
```bash
213-
aws kms describe-key --key-id arn:aws:kms:us-west-2:370957321024:key/9d989aa2-2f9c-438c-a745-cc57d3ad0126
214-
```
121+
### AWS Credentials
215122

216-
### Import Errors
217-
If you encounter import errors, ensure you're in the correct directory:
123+
Configure credentials using ada and assume the ddb role:
218124
```bash
219-
cd PerfTest/runtimes/python/DynamoDbEncryption
125+
# Configure ada credentials
126+
ada credentials update --provider isengard --role=ToolsDevelopment --once \
127+
--account 370957321024 --profile=aws-crypto-tools-team+optools-ci-ToolsDevelopment
128+
129+
# Set region and assume role for tests
130+
export AWS_REGION="us-west-2"
131+
TMP_ROLE=$(aws sts assume-role --role-arn "arn:aws:iam::370957321024:role/GitHub-CI-DDBEC-Dafny-Role-us-west-2" --role-session-name "${USER}-Tests-DBEC" --profile aws-crypto-tools-team+optools-ci-ToolsDevelopment)
132+
export TMP_ROLE
133+
export AWS_ACCESS_KEY_ID=$(echo "${TMP_ROLE}" | jq -r '.Credentials.AccessKeyId')
134+
export AWS_SECRET_ACCESS_KEY=$(echo "${TMP_ROLE}" | jq -r '.Credentials.SecretAccessKey')
135+
export AWS_SESSION_TOKEN=$(echo "${TMP_ROLE}" | jq -r '.Credentials.SessionToken')
136+
137+
# Verify credentials are working
138+
aws sts get-caller-identity
220139
```
221-
222-
## Notes
223-
224-
1. **KMS Rate Limits**: Be aware of AWS KMS rate limits when running extensive benchmarks
225-
2. **Network Latency**: KMS operations include network calls and may vary based on location
226-
3. **Hierarchy Keyring**: The current implementation uses a simplified version for testing
227-
4. **Most Recent Provider**: Uses an in-memory store for testing (production would use DynamoDB)
228-
229-
## Contributing
230-
231-
When adding new tests:
232-
1. Follow the existing pattern in `test_base.py`
233-
2. Add appropriate pytest markers (`@pytest.mark.v3` or `@pytest.mark.v4`)
234-
3. Include all three data types in parametrized tests
235-
4. Update this README with any new requirements
236-
237140
## License
238141

239-
This project is licensed under the Apache License 2.0. See the LICENSE file in the root directory.
142+
Licensed under the Apache License 2.0.

PerfTest/runtimes/python/DynamoDbEncryption/pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ addopts =
1313
--benchmark-sort=name
1414
--benchmark-autosave
1515
--benchmark-save-data
16+
--benchmark-min-rounds=3
17+
--benchmark-rounds=5
1618
markers =
1719
benchmark: mark test as a benchmark test
1820
v3: mark test as DDBEC v3 specific

0 commit comments

Comments
 (0)