Skip to content
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

[AWS Sqs] Add SqsIO.writeBatches for improved performance #26946

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

mosche
Copy link
Member

@mosche mosche commented May 31, 2023

This adds an additional writeBatches to SqsIO to improve throughput using the batch API with an async client.

The previous KinesisIo AsyncPutRecordsHandler became a general handler, so it can also be used for SQS (and others).

(closes #21429)


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI.

@mosche
Copy link
Member Author

mosche commented May 31, 2023

R: @aromanenko-dev
R: @psolomin

No rush on this one, I'll be off for quite a while mid next week.

@github-actions
Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

Copy link
Contributor

@psolomin psolomin left a comment

Choose a reason for hiding this comment

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

Hello!

I ran basic QA checks and did not find issues. Will go through the code deeper this week.

Found one inconvenience - when I try to run SqsIOIT against real AWS resources, I get:

> Task :sdks:java:io:amazon-web-services2:integrationTest

org.apache.beam.sdk.io.aws2.sqs.testing.SqsIOIT > testWriteThenRead FAILED
    software.amazon.awssdk.services.sqs.model.QueueDeletedRecentlyException: You must wait 60 seconds after deleting a queue before you can create another with the same name. (Service: Sqs, Status Code: 400, Request ID: 37bcbb71-8938-5711-afa0-e7860fc9d2d7)

This is thrown too if I run the suite two times without waiting 60 sec.

What do you think of making the queue name vary in different tests and in different test runs? Not sure about the latter, but I think making it different in two tests is good - allows running full suite without errors.

@mosche
Copy link
Member Author

mosche commented Jun 6, 2023

Thanks @psolomin, good catch. That shouldn't happen, I've fixed it.

Copy link
Contributor

@psolomin psolomin left a comment

Choose a reason for hiding this comment

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

Thank you for inviting me to review this, I've learnt some new things.

When I tried this with Flink runner, performance-wise, new writeBatches() managed to submit 100k records in a couple of minutes, while write() was at 1 - 2k / minute. Big difference 👏 Dynamic writes to 2 destinations also worked just fine.

The code looks good to me too, I've left only a couple of nitpicks.

I wonder though, should we keep the existing write() then, long term? Or make it as deprecated and eventually drop?

@@ -1328,7 +1332,7 @@ void addClientRecord(int recordBytes) {
}

@Override
public void addPutRecordsRequest(long latencyMillis, boolean isPartialRetry) {
public void addBatchWriteRequest(long latencyMillis, boolean isPartialRetry) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[side note] While reading this PR, I've noticed:

... Concurrency settings above the default have caused a bug in the AWS SDK v2. ...
public Write<T> withConcurrentRequests(int concurrentRequests)

Does it still hold after the recent bump of AWS SDK version? Should we create an issue for Beam to expose this setting once the AWS SDK is fixed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually not sure about this at the moment. I'll make a note and will have look into this later when back from my pto.

Copy link
Contributor

@aromanenko-dev aromanenko-dev left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM

I added a couple of minor notes, ptal.

Also, I was a bit confused to see the changes of KinesisIO as well, despite the fact that this PR titles about only SqsIO. Never mind but it would be more clear to split such PR into two ones or properly name it in the future.

@mosche
Copy link
Member Author

mosche commented Jul 11, 2023

I wonder though, should we keep the existing write() then, long term? Or make it as deprecated and eventually drop?

@psolomin I'm still wondering / unsure how to proceed. I was also considering to re-implement write using write batches internally...

@mosche
Copy link
Member Author

mosche commented Jul 11, 2023

Also, I was a bit confused to see the changes of KinesisIO as well, despite the fact that this PR titles about only SqsIO. Never mind but it would be more clear to split such PR into two ones or properly name it in the future.

The changes on the Kinesis side are just to extract some common base functionality, but nothing functional.

@mosche mosche force-pushed the BEAM-13415-SqsBatchWriter branch from 0f8c48c to 59c247f Compare July 11, 2023 12:00
@mosche mosche merged commit 08538eb into apache:master Jul 11, 2023
@mosche mosche deleted the BEAM-13415-SqsBatchWriter branch July 11, 2023 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SqsIO.write should be implemented using batch API
3 participants