Skip to content

Various performance optimization for CRT sync HTTP client #4776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Dec 13, 2023

Motivation and Context

Various performance optimization for CRT sync HTTP client:

  1. InputStreamSubscriber: not throw exception when close is invoked if it has buffered all content to avoid exception creation.
  2. InputStreamAdaptingHttpStreamResponseHandler: remove volatile for simplePublisher variable since it's unncesssary private volatile SimplePublisher<ByteBuffer> simplePublisher;
  3. InputStreamAdaptingHttpStreamResponseHandler: complete future as soon as streaming starts. Previously, the future completes after streaming has finished, which means we'll buffer all data in memory first before user starts to read from the inputstream

@zoewangg zoewangg requested a review from a team as a code owner December 13, 2023 20:30
@@ -125,6 +128,11 @@ public int read(byte[] bytes, int off, int len) {
@Override
public void close() {
synchronized (subscribeLock) {
// If it is done, no-op
if (inputStreamState.get().equals(State.STREAMING_DONE)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK will close the input stream once a request is finished and in this case, if we already have all data buffered and received, there's no need to raise exception (exception creation is expensive)

@@ -67,7 +67,7 @@ final class ClasspathSdkHttpServiceProvider<T> implements SdkHttpServiceProvider

@Override
public Optional<T> loadService() {
Queue<T> impls = new PriorityQueue<>(Comparator.comparingInt(o -> httpServicesPriority.getOrDefault(o.getClass(),
Queue<T> impls = new PriorityQueue<>(Comparator.comparingInt(o -> httpServicesPriority.getOrDefault(o.getClass().getName(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the bug I found during testing that the priority order was not honored. I updated tests accordingly to catch this issue

@@ -201,87 +194,6 @@ private void executeRequest(CrtAsyncRequestContext executionContext,
}
}

private static final class InputStreamAdaptingHttpStreamResponseHandler implements HttpStreamResponseHandler {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this class to a separate class.

@dagnir
Copy link
Contributor

dagnir commented Dec 13, 2023

Nice, can you give a brief overview of the optimizations?

@zoewangg zoewangg force-pushed the zoewang/master/crt-performanceOptimization branch from 4b58129 to 0a95cea Compare December 13, 2023 23:59
@zoewangg
Copy link
Contributor Author

Nice, can you give a brief overview of the optimizations?

yup, added it in the description

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions

75.3% Coverage on New Code (required ≥ 80%)
3.1% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

idea Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

@zoewangg zoewangg merged commit ba4a221 into feature/master/synccrtclient Dec 14, 2023
@zoewangg zoewangg deleted the zoewang/master/crt-performanceOptimization branch December 14, 2023 20:30
zoewangg added a commit that referenced this pull request Dec 15, 2023
* Synchronous CRT Http Client SPI with tests (#4405)

* implemented synchronous crt java http client with tests.

---------

Co-authored-by: Waqar Ahmed Khan <[email protected]>
Co-authored-by: Dongie Agnir <[email protected]>

* Various refactoring on CRT Sync HTTP Client (#4749)

* Make sure CRT resources are closed (#4753)

* Load HTTP implementations from classpath based on priority order (#4774)

* Various performance optimization for CRT sync HTTP client (#4776)

* Various performance optimization for CRT sync HTTP client

* Return as soon as the stream starts if there is a payload in sync http client

* Clean up tests and add changelog entry

* Bump minor version to 2.22.0

* UrlConnectionSdkHttpService should have higher priority than AwsCrtSdkHttpService

* Remove CrtResource.waitForNoResources() from integration tests because it increases test time and makes tests flaky especially when tests are running in parallel. We still verify it in wiremock tests and stability tests

---------

Co-authored-by: Jonathan M. Henson <[email protected]>
Co-authored-by: Waqar Ahmed Khan <[email protected]>
Co-authored-by: Dongie Agnir <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants