|
| 1 | +# Comprehensive Profiling Suite |
| 2 | + |
| 3 | +This guide explains how to use the comprehensive profiling suite for DynamoDB encryption performance testing with configurable options. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The comprehensive profiling suite (`profile_comprehensive.py`) allows you to systematically profile all combinations of: |
| 8 | + |
| 9 | +- **Test Base**: `item` (item encryption) vs `client` (EncryptedClient) |
| 10 | +- **Provider**: `aes`, `kms`, `hierarchy` (most recent/hierarchy keyring) |
| 11 | +- **Data Type**: `single`, `nested`, `flat` attributes |
| 12 | +- **Operation**: `encrypt`, `decrypt` |
| 13 | +- **Version**: `v3`, `v4` |
| 14 | + |
| 15 | +Note: Profiling High Level Client or KMS Operations would require AWS credentials. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +- Python 3.11 or higher |
| 20 | +- Poetry package manager |
| 21 | + |
| 22 | +## Setup |
| 23 | + |
| 24 | +### Install Poetry |
| 25 | + |
| 26 | +```bash |
| 27 | +# Install Poetry (if not already installed) |
| 28 | +curl -sSL https://install.python-poetry.org | python3 - |
| 29 | + |
| 30 | +# Or using pip |
| 31 | +pip install poetry |
| 32 | +``` |
| 33 | + |
| 34 | +### Install Dependencies |
| 35 | + |
| 36 | +```bash |
| 37 | +# Install all dependencies including dev dependencies |
| 38 | +poetry install |
| 39 | +``` |
| 40 | + |
| 41 | +## Quick Start |
| 42 | + |
| 43 | +### Quick Profiling for AES Only Operations(Do not need AWS Credentials) |
| 44 | + |
| 45 | +```bash |
| 46 | +python profile_comprehensive.py --test-bases item --providers aes --data-types single --version v4 |
| 47 | +``` |
| 48 | + |
| 49 | +### Profile All Combinations (Default) |
| 50 | +```bash |
| 51 | +# Profile all combinations with default settings (v4 only) |
| 52 | +python profile_comprehensive.py |
| 53 | + |
| 54 | +# Generated configurations: 36 total |
| 55 | +# 2 test bases × 3 providers × 3 data types × 2 operations × 1 version = 36 |
| 56 | +``` |
| 57 | + |
| 58 | +### Profile Specific Configurations |
| 59 | + |
| 60 | +```bash |
| 61 | +# Profile only AES provider with item-based tests |
| 62 | +python profile_comprehensive.py --test-bases item --providers aes |
| 63 | + |
| 64 | +# Profile only encrypt operations |
| 65 | +python profile_comprehensive.py --operations encrypt |
| 66 | + |
| 67 | +# Profile specific data types |
| 68 | +python profile_comprehensive.py --data-types single flat |
| 69 | + |
| 70 | +# Profile with more iterations for higher precision |
| 71 | +python profile_comprehensive.py --iterations 200 |
| 72 | +``` |
| 73 | + |
| 74 | +### Compare v3 vs v4 Performance |
| 75 | + |
| 76 | +```bash |
| 77 | +# Compare v3 and v4 for AES provider only |
| 78 | +python profile_comprehensive.py --versions v3 v4 --providers aes |
| 79 | + |
| 80 | +# Compare versions for all providers (72 configurations total) |
| 81 | +python profile_comprehensive.py --versions v3 v4 |
| 82 | +``` |
| 83 | + |
| 84 | +### Advanced Profiling |
| 85 | + |
| 86 | +```bash |
| 87 | +# Enable line-by-line profiling (requires line_profiler) |
| 88 | +python profile_comprehensive.py --line-profile --providers aes --data-types single |
| 89 | + |
| 90 | +# Custom output directory |
| 91 | +python profile_comprehensive.py --output-dir my_profiling_results |
| 92 | + |
| 93 | +# Profile specific combination for detailed analysis |
| 94 | +python profile_comprehensive.py \ |
| 95 | + --test-bases item \ |
| 96 | + --providers aes \ |
| 97 | + --data-types nested \ |
| 98 | + --operations encrypt \ |
| 99 | + --iterations 500 \ |
| 100 | + --line-profile |
| 101 | +``` |
| 102 | + |
| 103 | +## Configuration Options |
| 104 | + |
| 105 | +### Test Bases |
| 106 | + |
| 107 | +- **`item`**: Direct encryption using `encrypt_dynamodb_item()` and `decrypt_dynamodb_item()` |
| 108 | + - Lower overhead, focuses on core encryption/decryption performance |
| 109 | + - Best for profiling the encryption algorithms themselves |
| 110 | + |
| 111 | +- **`client`**: Encryption via `EncryptedClient` |
| 112 | + - Higher-level API with additional overhead |
| 113 | + - Best for profiling real-world usage patterns |
| 114 | + |
| 115 | +### Providers |
| 116 | + |
| 117 | +- **`aes`**: Raw AES encryption |
| 118 | + - Fastest option, no key management overhead |
| 119 | + - Uses fixed AES-256 key material |
| 120 | + |
| 121 | +- **`kms`**: AWS KMS key provider/keyring |
| 122 | + - Production-ready key management |
| 123 | + - Includes network calls to KMS (may be mocked in tests) |
| 124 | + |
| 125 | +- **`hierarchy`**: Hierarchy keyring (v4) / Most Recent key provider (v3) |
| 126 | + - Advanced key management with key derivation |
| 127 | + - Includes key caching and rotation capabilities |
| 128 | + |
| 129 | +### Data Types |
| 130 | + |
| 131 | +- **`single`**: Single attribute item |
| 132 | + - Minimal data, fastest encryption |
| 133 | + - Good for measuring base overhead |
| 134 | + |
| 135 | +- **`nested`**: Nested structure with maps and lists |
| 136 | + - Complex data structures |
| 137 | + - Tests serialization/deserialization performance |
| 138 | + |
| 139 | +- **`flat`**: Multiple flat attributes |
| 140 | + - Many attributes at the same level |
| 141 | + - Tests attribute action processing |
| 142 | + |
| 143 | +### Operations |
| 144 | + |
| 145 | +- **`encrypt`**: Measures encryption performance |
| 146 | +- **`decrypt`**: Measures decryption performance |
| 147 | + |
| 148 | +## Output Structure |
| 149 | + |
| 150 | +The profiling suite generates comprehensive reports in the specified output directory: |
| 151 | + |
| 152 | +``` |
| 153 | +comprehensive_profiling_results/ |
| 154 | +├── comprehensive_profiling_report.txt # Human-readable summary |
| 155 | +├── comprehensive_profiling_results.json # Machine-readable results |
| 156 | +├── v4_item_aes_single_encrypt.prof # cProfile data files |
| 157 | +├── v4_item_aes_single_encrypt.png # Call graphs (if graphviz available) |
| 158 | +├── v4_item_aes_single_decrypt.prof |
| 159 | +├── v4_client_kms_nested_encrypt.prof |
| 160 | +└── ... (one .prof file per configuration) |
| 161 | +``` |
| 162 | + |
| 163 | +## Report Analysis |
| 164 | + |
| 165 | +### Summary by Dimension |
| 166 | + |
| 167 | +The report includes performance summaries organized by: |
| 168 | + |
| 169 | +1. **Test Base**: Average performance for item vs client approaches |
| 170 | +2. **Provider**: Comparison of AES, KMS, and hierarchy performance |
| 171 | +3. **Data Type**: How data complexity affects performance |
| 172 | +4. **Operation**: Encrypt vs decrypt timing differences |
| 173 | + |
| 174 | +### Detailed Results |
| 175 | + |
| 176 | +For each configuration, the report includes: |
| 177 | + |
| 178 | +- Configuration details |
| 179 | +- Time per operation (milliseconds) |
| 180 | +- Throughput (operations per second) |
| 181 | +- Data size metrics |
| 182 | +- Size increase ratio (encrypted vs original) |
| 183 | +- Top 5 time-consuming functions |
| 184 | + |
| 185 | +### AWS Credentials |
| 186 | + |
| 187 | +Configure credentials using ada and assume the ddb role: |
| 188 | + |
| 189 | +```bash |
| 190 | +# Configure ada credentials |
| 191 | +ada credentials update --provider isengard --role=ToolsDevelopment --once \ |
| 192 | + --account 370957321024 --profile=aws-crypto-tools-team+optools-ci-ToolsDevelopment |
| 193 | + |
| 194 | +# Set region and assume role for tests |
| 195 | +export AWS_REGION="us-west-2" |
| 196 | +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) |
| 197 | +export TMP_ROLE |
| 198 | +export AWS_ACCESS_KEY_ID=$(echo "${TMP_ROLE}" | jq -r '.Credentials.AccessKeyId') |
| 199 | +export AWS_SECRET_ACCESS_KEY=$(echo "${TMP_ROLE}" | jq -r '.Credentials.SecretAccessKey') |
| 200 | +export AWS_SESSION_TOKEN=$(echo "${TMP_ROLE}" | jq -r '.Credentials.SessionToken') |
| 201 | + |
| 202 | +# Verify credentials are working |
| 203 | +aws sts get-caller-identity |
| 204 | +``` |
0 commit comments