aws / aws/aws-sdk-java-v2

Collections of async profiler collected enhancements

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

Description

### Describe the bug

While profiling [Apache James]() email server, that does an extensive usage of object storage (S3 driver) to store and retrieve email content, I noticed the overall calls though the S3 drivers could easily be optimized (CPU, memory allocation) and could thus contribute to make James a faster email server.

It started with a call noticed to `Pattern.compile` which, should be avoided. Using a pre-compiler regex is the way to go:

![Screenshot from 2022-04-18 13-11-47](https://user-images.githubusercontent.com/6928740/163763698-00fdd0c8-e73c-4058-b031-1feea879afd7.png)

(5% of CPU and 6.5% of memory allocation for S3 getObject calls)

On the other suspicious calls that I located, there are repeated calls to checksum algorithms parsing. The parsing itself does an iteration of the constants using stream API. Stream API, while handy (I love it!) comes with a cost... Here we could easily build a map to resolve the calls and not pay this price.

![Screenshot from 2022-04-18 13-16-21](https://user-images.githubusercontent.com/6928740/163764167-52ded90b-331a-4a1b-8429-5a7a13ae84f0.png)

(4.87% of CPU and 17.79% of memory allocation for S3 getObject calls)

Furthermore, path marshallers do compile their patterns on each runs. Java do not offer a way to reuse the format and forces to always re-parse it. This takes 2.14% of the CPU and 1.45% of memory allocation for S3 getObject calls - 2.85% and 1.75% if we count the all String.format call. Here the formatting is naive and can be replaced with string concatenation.

![Screenshot from 2022-04-18 13-24-51](https://user-images.githubusercontent.com/6928740/163765005-3436056c-f0a2-4469-ab63-8dab47ede19d.png)

Furthermore, the requestid log is being formatted while I never log it, which is wasteful. (This one was is AWS netty stack) I suggest formatting the log message lazily only if needed. This takes 2.4% of CPU dedicated to S3 (including background processes).

![Screenshot from 2022-04-18 13-30-20](https://user-images.githubusercontent.com/6928740/163765632-0b8dcb19-2f26-4215-89b0-3fbaeaaf1dc5.png)

### Expected Behavior

I would be glad to contribute some of these little performance improvements. This could improve performance of the S3 driver by a handful of percents for me and other users,

### Current Behavior

Currently the S3 driver spends significant amount of time/ memory on easy to optimize code.

### Reproduction Steps

Profiling S3 driver getObjects with Async profiler https://github.com/jvm-profiling-tools/async-profiler

### Possible Solution

- Use string concatenation in place of String.format in PathMarshalling
- Provide a map to back Algorithm lookups for checksum
- Use a preconpiled regex for regions
- Format requestId log only if needed

On that very one, the use of codegen [revented me to come up with a proposal as I just don't understand how codegen works...

### Additional Information/Context

Would a pull request on this be welcomed?

### AWS Java SDK version used

2.17.170

### JDK version used

openjdk version "11.0.14.1" 2022-02-08

### 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.