You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_Reducing memory consumption of the [AWS SDK for Java v2](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html) when loading an S3 object into memory_
4
+
5
+
This repo is for evaluation of different approaches to reducing memory consumption of the AWS SDK Java v2 [async](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/asynchronous.html)
The resulting PR is https://github.com/aws/aws-sdk-java-v2/pull/4355.
9
+
10
+
Approaches under consideration for reducing memory usage:
11
+
12
+
* Change A: Optimise byte storage, comes in two successive parts:
13
+
*[**A1**](https://github.com/rtyley/aws-sdk-async-response-bytes/pull/8): Use the Content Length to initialise the `ByteArrayOutputStream` with **a byte array of the right size**.
14
+
*[**A2**](https://github.com/rtyley/aws-sdk-async-response-bytes/pull/10): Use a simple fixed-size byte array in preference to a `ByteArrayOutputStream`
15
+
* Change [**B**](https://github.com/rtyley/aws-sdk-async-response-bytes/pull/12): Avoid performing a byte array copy when creating the `ResponseBytes` instance
16
+
17
+
Approaches A & B can be considered individually, but work much better when combined.
18
+
19
+
## Automated Memory-Consumption tests
20
+
3
21
The test script [`findMinMem.sh`](https://github.com/rtyley/aws-sdk-async-response-bytes/blob/ab9307fee6d4965cce0cba60c439035a22cf2d98/findMinMem.sh)
4
22
repeatedly downloads a [**258 MB**](https://github.com/rtyley/aws-sdk-async-response-bytes/blob/eb84c15259f947e91c442eb0b8eda68b8cdbefbb/src/main/java/com/madgag/aws/sdk/async/responsebytes/KnownS3Object.java#L7)
5
-
object from S3 into memory, while varying the amount of Java heap memory allocated with `-Xmx`,
6
-
to find the amount of memory necessary for the download to consistently succeed.
23
+
object from S3 into memory, while varying the amount of Java heap memory allocated with `-Xmx`,
24
+
to find the amount of memory necessary for the download to consistently succeed with the given
25
+
approach.
7
26
8
27
These are the resulting memory requirements found, in MB, for all possible permutations
9
28
of the fixes:
@@ -14,4 +33,11 @@ of the fixes:
14
33
| Include B |[787](https://github.com/rtyley/aws-sdk-async-response-bytes/actions/runs/6058093770#summary-16439898197)|[657](https://github.com/rtyley/aws-sdk-async-response-bytes/actions/runs/6058097434#summary-16439905403)|[357](https://github.com/rtyley/aws-sdk-async-response-bytes/actions/runs/6058098624#summary-16439907698)|
15
34
16
35
From the results, it's clear that we need all 3 changes (A1, A2, & B) in order
17
-
to get the lowest memory usage.
36
+
to get the lowest memory usage.
37
+
38
+
### Test details
39
+
40
+
* JVM invocation: [forked](https://github.com/rtyley/aws-sdk-async-response-bytes/blob/3d8e86870a86e035189d6f88b4e41e42be72ca82/build.sbt#L1) (for each invocation of `GetObject`)
41
+
* Invocation repetition count for success: [20](https://github.com/rtyley/aws-sdk-async-response-bytes/blob/3d8e86870a86e035189d6f88b4e41e42be72ca82/build.sbt#L17)
* Download integrity: [SHA-256 check against known hash](https://github.com/rtyley/aws-sdk-async-response-bytes/blob/main/src/main/java/com/madgag/aws/sdk/async/responsebytes/Main.java#L30)
0 commit comments