|
| 1 | +##################################### |
| 2 | +aws-encryption-sdk performance tests |
| 3 | +##################################### |
| 4 | + |
| 5 | +This module runs performance tests for the `AWS Encryption SDK Python`_. |
| 6 | + |
| 7 | +******** |
| 8 | +Overview |
| 9 | +******** |
| 10 | + |
| 11 | +This module tests the following keyrings / master key providers: |
| 12 | + |
| 13 | +1. KMS Keyring / KMS Master Key Provider |
| 14 | +2. Raw AES Keyring / AES Master Key Provider |
| 15 | +3. Raw RSA Keyring / RSA Master Key Provider |
| 16 | +4. Hierarchy Keyring |
| 17 | +5. Caching CMM |
| 18 | + |
| 19 | +For each test on the above keyrings / master key providers, this package measures: |
| 20 | + |
| 21 | +1. Execution time |
| 22 | +2. Total memory consumption |
| 23 | + |
| 24 | +For each keyring / master key provider, the execution time and memory consumption |
| 25 | +is measured for three operations: |
| 26 | + |
| 27 | +1. Create keyring / master key provider |
| 28 | +2. Encrypt |
| 29 | +3. Decrypt |
| 30 | + |
| 31 | +The usage of the performance tests is demonstrated through an `AWS KMS Keyring`_. |
| 32 | +However, the procedure is the same for any keyring / master key provider, with slight |
| 33 | +changes in the input arguments. |
| 34 | + |
| 35 | +The results for the performance test will be available in the results folder in the |
| 36 | +performance_tests directory. |
| 37 | + |
| 38 | +********************** |
| 39 | +Required Prerequisites |
| 40 | +********************** |
| 41 | + |
| 42 | +* Python 3.8+ |
| 43 | +* aws-encryption-sdk |
| 44 | +* boto3 >= 1.10.0 |
| 45 | +* click |
| 46 | +* tqdm |
| 47 | +* pytest |
| 48 | + |
| 49 | +Recommended Prerequisites |
| 50 | +========================= |
| 51 | + |
| 52 | +* aws-cryptographic-material-providers: >= 1.0.0 |
| 53 | + * Requires Python 3.11+. |
| 54 | + |
| 55 | +***** |
| 56 | +Usage |
| 57 | +***** |
| 58 | + |
| 59 | +Execution Time |
| 60 | +============== |
| 61 | + |
| 62 | +Create Keyring |
| 63 | +-------------- |
| 64 | +To run the performance test for execution time, please use the |
| 65 | +following commands in the performance_tests directory. |
| 66 | + |
| 67 | +.. code:: |
| 68 | +
|
| 69 | + usage: python test/keyrings/test_aws_kms_keyring.py create |
| 70 | +
|
| 71 | + Create a keyring to use for encryption and decryption. |
| 72 | +
|
| 73 | + optional arguments: |
| 74 | + -h, --help show this help message and exit. |
| 75 | + --kms_key_id KMS_KEY_ID The KMS key ID you want to use. |
| 76 | + --n_iters N_ITERS Number of iterations you want to |
| 77 | + run the test for. For instance, |
| 78 | + if n_iters = 100, this performance |
| 79 | + test script will run the create_keyring |
| 80 | + method 100 times and report the |
| 81 | + execution time of each of the calls. |
| 82 | + --output_file OUTPUT_FILE The output file for execution times |
| 83 | + for each function call, |
| 84 | + default='kms_keyring_create' in the |
| 85 | + results folder. |
| 86 | +
|
| 87 | +Encrypt |
| 88 | +------- |
| 89 | + |
| 90 | +To run the performance test for execution time, please use the following |
| 91 | +commands in the performance_tests directory: |
| 92 | + |
| 93 | +.. code:: |
| 94 | +
|
| 95 | + usage: python test/keyrings/test_aws_kms_keyring.py encrypt |
| 96 | +
|
| 97 | + optional arguments: |
| 98 | + -h, --help show this help message and exit. |
| 99 | + --plaintext_data_filename PLAINTEXT_DATA_FILENAME Filename containing plaintext data |
| 100 | + you want to encrypt. |
| 101 | + default='test/resources/plaintext/plaintext-data-medium.dat'. |
| 102 | + You can choose to use any other plaintext |
| 103 | + file as well. Some example plaintext |
| 104 | + data files are present in the |
| 105 | + 'test/resources' directory. |
| 106 | + --kms_key_id KMS_KEY_ID The KMS key ID you want to use. |
| 107 | + --n_iters N_ITERS Number of iterations you want to |
| 108 | + run the test for. For instance, |
| 109 | + if n_iters = 100, this performance |
| 110 | + test script will run the create_keyring |
| 111 | + method 100 times and report the |
| 112 | + execution time of each of the calls. |
| 113 | + --output_file OUTPUT_FILE The output file for execution times |
| 114 | + for each function call, |
| 115 | + default='kms_keyring_create' in the |
| 116 | + results folder. |
| 117 | +
|
| 118 | +Decrypt |
| 119 | +------- |
| 120 | + |
| 121 | +To run the performance test for execution time, please use the |
| 122 | +following commands in the performance_tests directory |
| 123 | + |
| 124 | +.. code:: |
| 125 | +
|
| 126 | + usage: python test/keyrings/test_aws_kms_keyring.py decrypt |
| 127 | +
|
| 128 | + optional arguments: |
| 129 | + -h, --help show this help message and exit. |
| 130 | + --ciphertext_data_filename CIPHERTEXT_DATA_FILENAME Filename containing ciphertext data |
| 131 | + you want to decrypt. |
| 132 | + default='test/resources/ciphertext/kms/ciphertext-data-medium.ct'. |
| 133 | + You can choose to use any other |
| 134 | + ciphertext file as well. Some example |
| 135 | + ciphertext data files are present in |
| 136 | + the 'test/resources' directory. |
| 137 | + --kms_key_id KMS_KEY_ID The KMS key ID you want to use. |
| 138 | + --n_iters N_ITERS Number of iterations you want to |
| 139 | + run the test for. For instance, |
| 140 | + if n_iters = 100, this performance |
| 141 | + test script will run the create_keyring |
| 142 | + method 100 times and report the |
| 143 | + execution time of each of the calls. |
| 144 | + --output_file OUTPUT_FILE The output file for execution times |
| 145 | + for each function call, |
| 146 | + default='kms_keyring_create' in the |
| 147 | + results folder. |
| 148 | +
|
| 149 | +Consolidate Time Results |
| 150 | +======================== |
| 151 | + |
| 152 | +In order to find the minimum, maximum, average, 99th percentile and bottom |
| 153 | +99th percentile trimmed average times from the n_iters runs, please use the |
| 154 | +following script from the performance_tests directory with the csv file |
| 155 | +containing times for each of the n_iters runs generated in the previous |
| 156 | +"Execution Time" section: |
| 157 | + |
| 158 | +.. code:: |
| 159 | +
|
| 160 | + usage: python consolidate_results.py results/kms_keyring_decrypt.csv |
| 161 | +
|
| 162 | +Memory Consumption |
| 163 | +================== |
| 164 | + |
| 165 | +To get the memory consumption, simply replace 'python' |
| 166 | +with 'mprof run' in the previously mentioned commands. |
| 167 | + |
| 168 | +For example, if you want to calculate the memory consumption |
| 169 | +of the encrypt function of a AWS KMS Keyring, simply write: |
| 170 | + |
| 171 | +.. code:: |
| 172 | +
|
| 173 | + usage: mprof run test/keyrings/test_aws_kms_keyring.py encrypt |
| 174 | +
|
| 175 | +
|
| 176 | +This should generate an mprofile log file in your current directory. |
| 177 | +This mprofile log file contains the total memory consumed by the program |
| 178 | +with respect to time elapsed. |
| 179 | +To plot the memory consumption with respect to time, please use the following |
| 180 | +command from the same directory |
| 181 | + |
| 182 | +.. code:: |
| 183 | +
|
| 184 | + usage: mprof plot |
| 185 | +
|
| 186 | +
|
| 187 | +This 'mprof plot' command will plot the most recent mprofile log file. |
| 188 | + |
| 189 | + |
| 190 | +Performance Graph |
| 191 | +================= |
| 192 | + |
| 193 | +To generate a performance graph, please use the following command |
| 194 | +to generate the pstats log file by specifying the output pstats file |
| 195 | +path. Here, 'results/kms_keyring_create.pstats' is set as the default |
| 196 | +output file. |
| 197 | + |
| 198 | +.. code:: |
| 199 | +
|
| 200 | + usage: python -m cProfile -o results/kms_keyring_create.pstats test/keyrings/test_aws_kms_keyring.py create |
| 201 | +
|
| 202 | +
|
| 203 | +After generating the pstats file, please run the following command |
| 204 | +to generate the performance graph. The output performance graph will |
| 205 | +be a .png file that you specify. Here, 'results/kms_keyring_create.png' |
| 206 | +is set as the default output file. |
| 207 | + |
| 208 | +.. code:: |
| 209 | +
|
| 210 | + usage: gprof2dot -f pstats results/kms_keyring_create.pstats | dot -Tpng -o results/kms_keyring_create.png && eog results/kms_keyring_create.png |
| 211 | +
|
| 212 | +
|
| 213 | +Note: This project does not adhere to semantic versioning; as such it |
| 214 | +makes no guarantees that functionality will persist across major, |
| 215 | +minor, or patch versions. |
| 216 | +**DO NOT** take a standalone dependency on this library. |
| 217 | + |
| 218 | +.. _AWS Encryption SDK Python: https://github.com/aws/aws-encryption-sdk-python/ |
| 219 | +.. _AWS KMS Keyring: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/use-kms-keyring.html |
0 commit comments