Skip to content

Commit 4660344

Browse files
committed
refactoring and fixes
1 parent f325071 commit 4660344

8 files changed

+97
-103
lines changed

performance_tests/README.rst

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ This module runs performance tests for the `AWS Encryption SDK Python`_.
88
Overview
99
********
1010

11-
This module tests the following keyrings / master key-providers:
11+
This module tests the following keyrings / master key providers:
1212

1313
1. KMS Keyring / KMS Master Key Provider
1414
2. Raw AES Keyring / AES Master Key Provider
1515
3. Raw RSA Keyring / RSA Master Key Provider
1616
4. Hierarchy Keyring
1717
5. Caching CMM
1818

19-
For each test on the above keyrings / master key-providers, this package measures:
19+
For each test on the above keyrings / master key providers, this package measures:
2020

2121
1. Execution time
2222
2. Total memory consumption
2323

24-
For each keyring / master key-provider, the execution time and memory consumption
24+
For each keyring / master key provider, the execution time and memory consumption
2525
is measured for three operations:
2626

27-
1. Create keyring / master key-provider
27+
1. Create keyring / master key provider
2828
2. Encrypt
2929
3. Decrypt
3030

3131
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
32+
However, the procedure is the same for any keyring / master key provider, with slight
3333
changes in the input arguments.
3434

3535
The results for the performance test will be available in the results folder in the
@@ -39,8 +39,18 @@ performance_tests directory.
3939
Required Prerequisites
4040
**********************
4141

42-
* Python 3.11+
42+
* Python 3.8+
4343
* 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+.
4454

4555
*****
4656
Usage
@@ -74,19 +84,6 @@ following commands in the performance_tests directory.
7484
default='kms_keyring_create' in the
7585
results folder.
7686
77-
78-
Consolidate Results
79-
~~~~~~~~~~~~~~~~~~~
80-
81-
In order to find the minimum, maximum, average, 99th percentile and bottom
82-
99th percentile trimmed average times from the n_iters runs, please use the
83-
following script from the performance_tests directory:
84-
85-
.. code::
86-
87-
usage: python consolidate_results.py results/kms_keyring_create.csv
88-
89-
9087
Encrypt
9188
-------
9289

@@ -118,18 +115,6 @@ commands in the performance_tests directory:
118115
default='kms_keyring_create' in the
119116
results folder.
120117
121-
Consolidate Results
122-
~~~~~~~~~~~~~~~~~~~
123-
124-
In order to find the minimum, maximum, average, 99th percentile and bottom
125-
99th percentile trimmed average times from the n_iters runs, please use the
126-
following script from the performance_tests directory:
127-
128-
.. code::
129-
130-
usage: python consolidate_results.py results/kms_keyring_encrypt.csv
131-
132-
133118
Decrypt
134119
-------
135120

@@ -161,12 +146,14 @@ following commands in the performance_tests directory
161146
default='kms_keyring_create' in the
162147
results folder.
163148
164-
Consolidate Results
165-
~~~~~~~~~~~~~~~~~~~
149+
Consolidate Time Results
150+
========================
166151

167152
In order to find the minimum, maximum, average, 99th percentile and bottom
168153
99th percentile trimmed average times from the n_iters runs, please use the
169-
following script from the performance_tests directory:
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:
170157

171158
.. code::
172159

performance_tests/consolidate_results.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ def calculate_statistics(_csv_file):
1414
reader = csv.reader(file)
1515
data = [float(row[0]) for row in reader]
1616

17+
output_stats = {}
18+
1719
# Calculate statistics
1820
if data:
1921
data = np.sort(data)
20-
_total_entries = len(data)
21-
_average = np.mean(data)
22-
_trimmed_average_99_bottom = np.mean(data[0:int(0.99 * len(data))])
23-
_minimum = min(data)
24-
_maximum = max(data)
25-
_perc_99 = np.percentile(data, 99)
26-
return _total_entries, _average, _trimmed_average_99_bottom, _minimum, _maximum, _perc_99
22+
output_stats['total_entries'] = len(data)
23+
output_stats['average'] = np.mean(data)
24+
output_stats['trimmed_average_99_bottom'] = np.mean(data[0:int(0.99 * len(data))])
25+
output_stats['minimum'] = min(data)
26+
output_stats['maximum'] = max(data)
27+
output_stats['perc_99'] = np.percentile(data, 99)
28+
return output_stats
2729

2830
return None
2931

@@ -36,13 +38,12 @@ def calculate_statistics(_csv_file):
3638

3739
statistics = calculate_statistics(args.csv_file)
3840
if statistics:
39-
total_entries, average, trimmend_average_99_bottom, minimum, maximum, perc_99 = statistics
4041
print("CSV File:", args.csv_file)
41-
print("Total Entries:", total_entries)
42-
print("Average:", average)
43-
print("Bottom 99th percentile trimmed average:", trimmend_average_99_bottom)
44-
print("Minimum:", minimum)
45-
print("Maximum:", maximum)
46-
print("99th percentile:", perc_99)
42+
print("Total Entries:", statistics['total_entries'])
43+
print("Average:", statistics['average'])
44+
print("Bottom 99th percentile trimmed average:", statistics['trimmed_average_99_bottom'])
45+
print("Minimum:", statistics['minimum'])
46+
print("Maximum:", statistics['maximum'])
47+
print("99th percentile:", statistics['perc_99'])
4748
else:
4849
print("No data found in the CSV file.")

performance_tests/test/keyrings/test_aws_kms_keyring.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""This is a performance test for creating the AWS KMS keyring."""
44

5+
import os
56
import time
67

78
import click
@@ -18,6 +19,8 @@
1819
)
1920
from aws_encryption_sdk_performance_tests.utils.util import PerfTestUtils
2021

22+
MODULE_ABS_PATH = os.path.abspath(__file__)
23+
2124

2225
@click.group()
2326
def create_kms_keyring():
@@ -30,7 +33,7 @@ def create_kms_keyring():
3033
@click.option('--n_iters',
3134
default=PerfTestUtils.DEFAULT_N_ITERS)
3235
@click.option('--output_file',
33-
default='/'.join(__file__.split("/")[:-3]) + '/results/kms_keyring_create')
36+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/kms_keyring_create')
3437
def create(
3538
kms_key_id: str,
3639
n_iters: int,
@@ -60,7 +63,7 @@ def create_kms_keyring_given_kms_client():
6063
@click.option('--n_iters',
6164
default=PerfTestUtils.DEFAULT_N_ITERS)
6265
@click.option('--output_file',
63-
default='/'.join(__file__.split("/")[:-3]) + '/results/kms_keyring_create_given_kms_client')
66+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/kms_keyring_create_given_kms_client')
6467
def create_given_kms_client(
6568
kms_key_id: str,
6669
n_iters: int,
@@ -88,15 +91,14 @@ def encrypt_kms_keyring():
8891

8992
@encrypt_kms_keyring.command()
9093
@click.option('--plaintext_data_filename',
91-
default='/'.join(__file__.split("/")[:-2]) + '/resources/plaintext/plaintext-data-'
92-
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.dat',
93-
prompt='Filename containing plaintext data you want to encrypt')
94+
default='/'.join(MODULE_ABS_PATH.split("/")[:-2]) + '/resources/plaintext/plaintext-data-'
95+
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.dat')
9496
@click.option('--kms_key_id',
9597
default='arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f')
9698
@click.option('--n_iters',
9799
default=PerfTestUtils.DEFAULT_N_ITERS)
98100
@click.option('--output_file',
99-
default='/'.join(__file__.split("/")[:-3]) + '/results/kms_keyring_encrypt')
101+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/kms_keyring_encrypt')
100102
def encrypt(
101103
plaintext_data_filename: str,
102104
kms_key_id: str,
@@ -128,15 +130,14 @@ def decrypt_kms_keyring():
128130

129131
@decrypt_kms_keyring.command()
130132
@click.option('--ciphertext_data_filename',
131-
default='/'.join(__file__.split("/")[:-2]) + '/resources/ciphertext/kms/ciphertext-data-'
132-
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.ct',
133-
prompt='Filename containing ciphertext data you want to decrypt')
133+
default='/'.join(MODULE_ABS_PATH.split("/")[:-2]) + '/resources/ciphertext/kms/ciphertext-data-'
134+
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.ct')
134135
@click.option('--kms_key_id',
135136
default='arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f')
136137
@click.option('--n_iters',
137138
default=PerfTestUtils.DEFAULT_N_ITERS)
138139
@click.option('--output_file',
139-
default='/'.join(__file__.split("/")[:-3]) + '/results/kms_keyring_decrypt')
140+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/kms_keyring_decrypt')
140141
def decrypt(
141142
ciphertext_data_filename: str,
142143
kms_key_id: str,

performance_tests/test/keyrings/test_raw_aes_keyring.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""This is a performance test for creating the Raw AES keyring."""
44

5+
import os
56
import time
67

78
import click
@@ -16,6 +17,8 @@
1617
)
1718
from aws_encryption_sdk_performance_tests.utils.util import PerfTestUtils
1819

20+
MODULE_ABS_PATH = os.path.abspath(__file__)
21+
1922

2023
@click.group()
2124
def create_raw_aes_keyring():
@@ -26,7 +29,7 @@ def create_raw_aes_keyring():
2629
@click.option('--n_iters',
2730
default=PerfTestUtils.DEFAULT_N_ITERS)
2831
@click.option('--output_file',
29-
default='/'.join(__file__.split("/")[:-3]) + '/results/raw_aes_keyring_create')
32+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/raw_aes_keyring_create')
3033
def create(
3134
n_iters: int,
3235
output_file: str
@@ -52,13 +55,12 @@ def encrypt_raw_aes_keyring():
5255

5356
@encrypt_raw_aes_keyring.command()
5457
@click.option('--plaintext_data_filename',
55-
default='/'.join(__file__.split("/")[:-2]) + '/resources/plaintext/plaintext-data-'
56-
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.dat',
57-
prompt='Filename containing plaintext data you want to encrypt')
58+
default='/'.join(MODULE_ABS_PATH.split("/")[:-2]) + '/resources/plaintext/plaintext-data-'
59+
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.dat')
5860
@click.option('--n_iters',
5961
default=PerfTestUtils.DEFAULT_N_ITERS)
6062
@click.option('--output_file',
61-
default='/'.join(__file__.split("/")[:-3]) + '/results/raw_aes_keyring_encrypt')
63+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/raw_aes_keyring_encrypt')
6264
def encrypt(
6365
plaintext_data_filename: str,
6466
n_iters: int,
@@ -89,13 +91,12 @@ def decrypt_raw_aes_keyring():
8991

9092
@decrypt_raw_aes_keyring.command()
9193
@click.option('--ciphertext_data_filename',
92-
default='/'.join(__file__.split("/")[:-2]) + '/resources/ciphertext/raw_aes/ciphertext-data-'
93-
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.ct',
94-
prompt='Filename containing ciphertext data you want to decrypt')
94+
default='/'.join(MODULE_ABS_PATH.split("/")[:-2]) + '/resources/ciphertext/raw_aes/ciphertext-data-'
95+
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.ct')
9596
@click.option('--n_iters',
9697
default=PerfTestUtils.DEFAULT_N_ITERS)
9798
@click.option('--output_file',
98-
default='/'.join(__file__.split("/")[:-3]) + '/results/raw_aes_keyring_decrypt')
99+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/raw_aes_keyring_decrypt')
99100
def decrypt(
100101
ciphertext_data_filename: str,
101102
n_iters: int,

performance_tests/test/keyrings/test_raw_rsa_keyring.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""This is a performance test for creating the Raw RSA keyring."""
44

5+
import os
56
import time
67

78
import click
@@ -16,6 +17,8 @@
1617
)
1718
from aws_encryption_sdk_performance_tests.utils.util import PerfTestUtils
1819

20+
MODULE_ABS_PATH = os.path.abspath(__file__)
21+
1922

2023
@click.group()
2124
def create_raw_rsa_keyring():
@@ -26,7 +29,7 @@ def create_raw_rsa_keyring():
2629
@click.option('--n_iters',
2730
default=PerfTestUtils.DEFAULT_N_ITERS)
2831
@click.option('--output_file',
29-
default='/'.join(__file__.split("/")[:-3]) + '/results/raw_rsa_keyring_create')
32+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/raw_rsa_keyring_create')
3033
def create(
3134
n_iters: int,
3235
output_file: str
@@ -55,13 +58,12 @@ def encrypt_raw_rsa_keyring():
5558

5659
@encrypt_raw_rsa_keyring.command()
5760
@click.option('--plaintext_data_filename',
58-
default='/'.join(__file__.split("/")[:-2]) + '/resources/plaintext/plaintext-data-'
59-
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.dat',
60-
prompt='Filename containing plaintext data you want to encrypt')
61+
default='/'.join(MODULE_ABS_PATH.split("/")[:-2]) + '/resources/plaintext/plaintext-data-'
62+
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.dat')
6163
@click.option('--n_iters',
6264
default=PerfTestUtils.DEFAULT_N_ITERS)
6365
@click.option('--output_file',
64-
default='/'.join(__file__.split("/")[:-3]) + '/results/raw_rsa_keyring_encrypt')
66+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/raw_rsa_keyring_encrypt')
6567
def encrypt(
6668
plaintext_data_filename: str,
6769
n_iters: int,
@@ -94,13 +96,12 @@ def decrypt_raw_rsa_keyring():
9496

9597
@decrypt_raw_rsa_keyring.command()
9698
@click.option('--ciphertext_data_filename',
97-
default='/'.join(__file__.split("/")[:-2]) + '/resources/ciphertext/raw_rsa/ciphertext-data-'
98-
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.ct',
99-
prompt='Filename containing ciphertext data you want to decrypt')
99+
default='/'.join(MODULE_ABS_PATH.split("/")[:-2]) + '/resources/ciphertext/raw_rsa/ciphertext-data-'
100+
+ PerfTestUtils.DEFAULT_FILE_SIZE + '.ct')
100101
@click.option('--n_iters',
101102
default=PerfTestUtils.DEFAULT_N_ITERS)
102103
@click.option('--output_file',
103-
default='/'.join(__file__.split("/")[:-3]) + '/results/raw_rsa_keyring_decrypt')
104+
default='/'.join(MODULE_ABS_PATH.split("/")[:-3]) + '/results/raw_rsa_keyring_decrypt')
104105
def decrypt(
105106
ciphertext_data_filename: str,
106107
n_iters: int,

0 commit comments

Comments
 (0)