Increase memory to avoid OOM errors during download#8
Merged
Conversation
The GeoIp file has grown _slightly_ larger (from 134368384 to 134801401 bytes) - and now we're seeing consistent OutOfMemoryErrors?! Memory usage as reported at the end of an unsuccessful run with 512MB: > REPORT RequestId: 8f4b33f4-8913-4095-9bfa-3b1f64fd1e6a Duration: 38466.58 ms Billed Duration: 38467 ms Memory Size: 512 MB Max Memory Used: 395 MB We increased memory size to 1024MB, and the function ran successfully: > REPORT RequestId: b4a76e3b-581d-4296-a613-0ca50ec92e2f Duration: 19931.72 ms Billed Duration: 19932 ms Memory Size: 1024 MB Max Memory Used: 750 MB Init Duration: 416.56 ms ...this would indicate, for the time being at least, we need a minimum of 750 MB for this lambda. It's surprisingly inefficent given the streaming code involved though 😢 ``` Java heap space: java.lang.OutOfMemoryError java.lang.OutOfMemoryError: Java heap space at java.base/java.util.Arrays.copyOf(Unknown Source) at java.base/java.io.ByteArrayOutputStream.grow(Unknown Source) at java.base/java.io.ByteArrayOutputStream.ensureCapacity(Unknown Source) at java.base/java.io.ByteArrayOutputStream.write(Unknown Source) at java.base/sun.net.www.http.PosterOutputStream.write(Unknown Source) at software.amazon.awssdk.utils.IoUtils.copy(IoUtils.java:113) at software.amazon.awssdk.utils.IoUtils.copy(IoUtils.java:99) at software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient$RequestCallable.lambda$null$0(UrlConnectionHttpClient.java:208) at software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient$RequestCallable$$Lambda$437/0x000000084036d840.get(Unknown Source) at software.amazon.awssdk.utils.FunctionalUtils.lambda$safeSupplier$4(FunctionalUtils.java:108) at software.amazon.awssdk.utils.FunctionalUtils$$Lambda$77/0x000000084016e840.get(Unknown Source) at software.amazon.awssdk.utils.FunctionalUtils.invokeSafely(FunctionalUtils.java:136) at software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient$RequestCallable.lambda$call$1(UrlConnectionHttpClient.java:208) at software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient$RequestCallable$$Lambda$436/0x000000084036e440.accept(Unknown Source) at java.base/java.util.Optional.ifPresent(Unknown Source) at software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient$RequestCallable.call(UrlConnectionHttpClient.java:207) at software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient$RequestCallable.call(UrlConnectionHttpClient.java:193) at software.amazon.awssdk.core.internal.util.MetricUtils.measureDurationUnsafe(MetricUtils.java:64) at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeHttpRequestStage.executeHttpRequest(MakeHttpRequestStage.java:76) at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeHttpRequestStage.execute(MakeHttpRequestStage.java:55) at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeHttpRequestStage.execute(MakeHttpRequestStage.java:39) at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206) at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206) at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206) at software.amazon.awssdk.core.internal.http.pipeline.RequestPipelineBuilder$ComposingRequestPipelineStage.execute(RequestPipelineBuilder.java:206) at software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptTimeoutTrackingStage.execute(ApiCallAttemptTimeoutTrackingStage.java:73) at software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptTimeoutTrackingStage.execute(ApiCallAttemptTimeoutTrackingStage.java:42) at software.amazon.awssdk.core.internal.http.pipeline.stages.TimeoutExceptionHandlingStage.execute(TimeoutExceptionHandlingStage.java:78) at software.amazon.awssdk.core.internal.http.pipeline.stages.TimeoutExceptionHandlingStage.execute(TimeoutExceptionHandlingStage.java:40) at software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptMetricCollectionStage.execute(ApiCallAttemptMetricCollectionStage.java:50) at software.amazon.awssdk.core.internal.http.pipeline.stages.ApiCallAttemptMetricCollectionStage.execute(ApiCallAttemptMetricCollectionStage.java:36) at software.amazon.awssdk.core.internal.http.pipeline.stages.RetryableStage.execute(RetryableStage.java:64) ``` Relates to #7 Co-authored-by: Roberto Tyley <roberto.tyley@guardian.co.uk>
lmath
approved these changes
Nov 10, 2021
rtyley
added a commit
that referenced
this pull request
Dec 8, 2021
AWS SDK v2.17.97 includes aws/aws-sdk-java-v2#2848, which lowers memory consumption by streaming request data, rather than loading the entire request into memory before sending it, which can make a large difference to consumption of memory when uploading large files to S3. In the case of the `geoip-db-refresher`, it's actually economical to run with _more_ RAM than we need (we're billed for fewer GB-seconds when specifying a `MemorySize` of 1536MB than 1024MB, as AWS Lambdas are given more CPU to match increased memory) so this is no longer a serious issue for the 134MB file uploaded here! See also: * #7 * #8 * 1de50ef * https://aws.amazon.com/lambda/pricing/ * https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html#configuration-memory-console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The GeoIp file has grown slightly larger (from 134368384 to 134801401 bytes) - and now we're seeing consistent OutOfMemoryErrors?!
Memory usage as reported at the end of an unsuccessful run with 512MB:
We increased memory size to 1024MB, and the function ran successfully:
...this would indicate, for the time being at least, we need a minimum of 750 MB for this lambda. It's surprisingly inefficent given the streaming code involved though 😢
This was causing builds to fail, but increasing the memory in the Lambda console has fixed the issue:
The Cloudformation stack has been updated to reflect this new value too:
Closes #7