awslabs / aws-sdk-swift

Apache License 2.0
400 stars 80 forks source link

Delays in Amplify SDK requests #1035

Closed jbelkins closed 1 year ago

jbelkins commented 1 year ago

Describe the bug

Amplify reports that Cognito auth requests sent via the SDK for Swift are being delayed about 2 sec: https://github.com/aws-amplify/amplify-swift/issues/3007

Investigate to see if this can be reproduced, and what the potential cause might be.

Expected Behavior

Requests are made immediately when the SDK operation is called

Current Behavior

Requests are delayed about 2 sec (see logs in attached Amplify ticket)

Reproduction Steps

Not immediately known, will investigate

Possible Solution

No response

Additional Information/Context

No response

AWS SWIFT SDK version used

0.13.0

Compiler and Version used

See attached

Operating System and version

See attached

jbelkins commented 1 year ago

Time box to a day of investigation

jbelkins commented 1 year ago

Was unable to reproduce. Awaiting further reproduction code samples or instructions from the reporters.

jbelkins commented 1 year ago

Attempt to reproduce using sample code provided in the linked Amplify ticket.

dayaffe commented 1 year ago

It looks like I am able to reproduce the issue using the provided amplify project AmplifySlowLogin

jbelkins commented 1 year ago

Investigated, and the reason is that HTTP connection pools are never being reused, and a new HTTP connection must be established prior to every HTTP request.

I will work with CRT to ensure that we reuse connection pools appropriately, and that we manage connections per the Smithy Reference Architecture.

fzy-github commented 1 year ago

hey, do you have any update on the issue above?

jbelkins commented 1 year ago

@fzy-spyro I am working on the solution now. We have a significant amount of work to do on the SDK's connection pooling logic but prior to that, I will find an interim solution that fixes this performance issue without causing problems elsewhere.

I will update here when a fix has been applied to the AWS SDK for Swift. Once that happens, Amplify will have to integrate it into an amplify-swift release.

jbelkins commented 1 year ago

The fix for this issue is expected to ship in AWS SDK for Swift next week. Once that happens, a new amplify-swift version will have to be shipped as well, incorporating the fixed version of this SDK.

Thanks for your patience while we addressed this issue.

fzy-github commented 1 year ago

this is great news, thanks!

jbelkins commented 1 year ago

Released in aws-sdk-swift 0.31.0.

Note that HTTP connections are not used across AWS clients; i.e. if you create two S3 clients, they do not share HTTP connections between them. We recommend that customers create one AWS service client per service per app launch, and keep a reference to the client for future use.

harsh62 commented 9 months ago

@jbelkins Can we please reopen the issue? The customer has reported that the issue is still not fixed and they are still facing the same problem.

jbelkins commented 9 months ago

@harsh62 AWS SDK for Swift 0.34.0 makes a new, URLSession-based HTTP client the default on all Apple platforms. That client does not use the connection pooling mechanism that was at fault in this original issue, and should overall be better suited to use on the platforms supported by amplify-swift.

Best solution to the problem would be to update amplify-swift to use version 0.34.0+ of this SDK.