aws / aws/aws-sdk-java-v2

Expensive instanciation of RetryPolicyContext upon requestSucceeded

Open
#3,194 4 comments 0 reactions 0 assignees View on GitHub
feature-request p2
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

### Describe the bug

The default retry condition combines sub elements that does nothing upon request success.

Yet we pay for every request the price of instanciating the RetryPolicyContext despite not using it. This looks wasteful.

### Expected Behavior

I expect reduced object creation linked to retry policies when my requests succeeds.

### Current Behavior

On a regular IMAP workload for the [Apache James](https://james.apache.org) server, I observe 0.74% percent of memory allocation to be caused by retry policy handling.

Note that S3 is only part of the workload, a bench exercising just S3 would actually show higher numbers here.

![Screenshot from 2022-05-16 12-01-42](https://user-images.githubusercontent.com/6928740/168523673-09aa2167-e17e-4f3f-905c-23da7b29c77a.png)

### Reproduction Steps

Profiling: https://github.com/jvm-profiling-tools/async-profiler

### Possible Solution

- 1. An additional level of indirection in the retry policies could enable passing a `Supplier` wich would both:
- A memoized supplier (a la Guava) that enables not instanciating the RetryPolicyCOntext until it is needed.
- Enable trivial implementation of the existing API to avoid breaking changes

- 2. Avoiding the iterator madness in the defaultRetryCondition.
- This could be done either by emptyness checks before iterations
- Or maybe overloading the `requestSucceeded` of the default retry condition to do nothing.

### Additional Information/Context

_No response_

### AWS Java SDK version used

2.17.189

### JDK version used

openjdk version "11.0.15" 2022-04-19

### Operating System and version

Ubuntu 20.04.4 LTS

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.