|
1 |
| -# AWS Database Encryption SDK - DynamoDB Performance Tests |
| 1 | +# Python Performance Tests: DDBEC v3 vs DB-ESDK v4 |
2 | 2 |
|
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). |
4 | 4 |
|
5 | 5 | ## Overview
|
6 | 6 |
|
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. |
8 | 8 |
|
9 |
| -### DDBEC v3 Providers |
| 9 | +### Libraries Under Test |
| 10 | + |
| 11 | +**DDBEC v3 Providers:** |
10 | 12 | - AES Key Provider
|
11 | 13 | - AWS KMS Key Provider
|
12 | 14 | - Most Recent Key Provider
|
13 | 15 |
|
14 |
| -### DB-ESDK v4 Keyrings |
| 16 | +**DB-ESDK v4 Keyrings:** |
15 | 17 | - Raw AES Keyring
|
16 | 18 | - 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 |
25 | 20 |
|
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 |
29 | 25 |
|
30 |
| -## Installation |
| 26 | +## Quick Start |
31 | 27 |
|
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` |
36 | 33 |
|
37 |
| -2. Install dependencies: |
| 34 | +### Installation |
38 | 35 | ```bash
|
39 |
| -poetry install --with test |
| 36 | +cd PerfTest/runtimes/python/DynamoDbEncryption |
| 37 | +poetry install |
40 | 38 | ```
|
41 | 39 |
|
42 |
| -## Running the Tests |
43 |
| - |
44 |
| -### Using Tox (Recommended) |
45 |
| - |
46 |
| -Run all performance tests: |
| 40 | +### Run All Benchmarks |
47 | 41 | ```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 |
58 | 42 | tox -e run-benchmarks
|
59 |
| -``` |
60 | 43 |
|
61 |
| -### Using Poetry Directly |
| 44 | +# Or |
| 45 | +python run_benchmarks.py |
62 | 46 |
|
63 |
| -```bash |
64 |
| -# Run all tests |
65 |
| -poetry run pytest src/ --benchmark-only |
66 |
| - |
67 |
| -# Run the benchmark script |
| 47 | +# Or using poetry |
68 | 48 | poetry run python run_benchmarks.py
|
69 | 49 | ```
|
70 | 50 |
|
71 |
| -### Command Line Options |
| 51 | +## Usage Examples |
72 | 52 |
|
| 53 | +### Basic Commands |
73 | 54 | ```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 |
83 | 57 |
|
84 |
| -### Examples with Tox |
| 58 | +# Test only DDBEC v3 |
| 59 | +python run_benchmarks.py --version v3 |
85 | 60 |
|
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 |
91 | 63 |
|
92 |
| -# Run linting |
93 |
| -tox -e lint |
| 64 | +# Test specific provider (AES, KMS, etc.) |
| 65 | +python run_benchmarks.py --test kms |
94 | 66 |
|
95 |
| -# Format code |
96 |
| -tox -e format |
| 67 | +# Test only encryption operations |
| 68 | +python run_benchmarks.py --test encrypt |
97 | 69 | ```
|
98 | 70 |
|
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 |
110 | 75 |
|
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 |
115 | 78 |
|
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 | +``` |
120 | 82 |
|
121 | 83 | ### Direct pytest Usage
|
122 |
| -
|
123 |
| -You can also run pytest directly with more control: |
124 |
| -
|
125 | 84 | ```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 |
131 | 87 |
|
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 |
134 | 90 |
|
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 |
141 | 93 | ```
|
142 | 94 |
|
143 | 95 | ## Output
|
144 | 96 |
|
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: |
173 | 98 |
|
| 99 | +### Console Report |
174 | 100 | ```
|
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) (%) |
195 | 105 | ```
|
196 | 106 |
|
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 |
198 | 111 |
|
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. |
201 | 113 |
|
202 |
| -## Troubleshooting |
| 114 | +## Understanding Results |
203 | 115 |
|
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) |
209 | 120 |
|
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 |
215 | 122 |
|
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: |
218 | 124 | ```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 |
220 | 139 | ```
|
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 |
| - |
237 | 140 | ## License
|
238 | 141 |
|
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. |
0 commit comments