-
Notifications
You must be signed in to change notification settings - Fork 914
Internal classes and RequestBatchManager Impelementation #5418
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
Internal classes and RequestBatchManager Impelementation #5418
Conversation
2ae8af6
to
d78d204
Compare
d78d204
to
1a3b8e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it seems like we're still carrying over some of complexity from the original feature that intended to support batching across multiple services. Since we know that this is all going to be SQS specific can we simplify this design further, knowing that we just need to support SQS?
import software.amazon.awssdk.utils.Either; | ||
|
||
@SdkInternalApi | ||
public final class SqsBatchFunctions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a strange pattern since these look like they're only used for DefaultSqsAsyncBatchManager
. Any reason this isn't an abstract class instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This had private constructor , anyways made it abstract now.
Do you want to make it abstract and make DefaultSqsAsyncBatchManager extend SqsBatchFunctions ?
...main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/core/BatchKeyMapper.java
Outdated
Show resolved
Hide resolved
...rc/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/core/BatchBuffer.java
Outdated
Show resolved
Hide resolved
|
||
// Flushes the buffer for the given batchKey and fills in the response map with the returned responses. | ||
// Returns exception in completableFuture if batchingFunction.apply throws an exception. | ||
private void flushBuffer(String batchKey, Map<String, BatchingExecutionContext<RequestT, ResponseT>> flushableRequests) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't it just return the response map instead of taking it as an argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to keep the track of individual requests that were send and update those requests with its corresponding response. While sending we create unique ids for messages and while receiving we map it back.
Note that flushBuffer is done asynchronously and we are not returning any values but updating the CompletableFutures of the responses from the map, I can explain you this offline .
...java/software/amazon/awssdk/services/sqs/internal/batchmanager/core/RequestBatchManager.java
Outdated
Show resolved
Hide resolved
I removed the Generic Interface for BatchManager and will have sepaarte Batch Manager for Response and Request. |
private final BatchAndSend<RequestT, BatchResponseT> batchFunction; | ||
private final BatchResponseMapper<BatchResponseT, ResponseT> responseMapper; | ||
private final BatchKeyMapper<RequestT> batchKeyMapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should just be protected abstract
methods:
protected abstract CompletableFuture<BatchResponseT> batchAndSend(List<IdentifiableMessage<RequestT>> identifiedRequests,
String batchKey);
protected abstract String getBatchKey(RequestT request);
protected abstract List<Either<IdentifiableMessage<ResponseT>, IdentifiableMessage<Throwable>>> mapBatchResponse(BatchResponseT batchResponse);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
this.responseMapper = Validate.notNull(builder.responseMapper, "Null responseMapper"); | ||
this.batchKeyMapper = Validate.notNull(builder.batchKeyMapper, "Null batchKeyMapper"); | ||
this.scheduledExecutor = Validate.notNull(builder.scheduledExecutor, "Null scheduledExecutor"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need these right? See comment above re: making these protected abstract methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeap , removed these
@@ -12,6 +12,7 @@ | |||
} | |||
}, | |||
|
|||
"enableGenerateCompiledEndpointRules": true | |||
"enableGenerateCompiledEndpointRules": true, | |||
"batchManagerSupported": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be more generic now that batch managers could differ between services, e.g. where the actual FQCN, construct method, and argument are all specified? Maybe similar to the way the utilities()
method is generated?
aws-sdk-java-v2/services/s3/src/main/resources/codegen-resources/customization.config
Line 285 in 4f967b9
"utilitiesMethod": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are providing static method for BatchManager we cannot use the existing customizations also discussed in
#5321 (comment)
...sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/BatchingMap.java
Outdated
Show resolved
Hide resolved
...main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/RequestBatchManager.java
Show resolved
Hide resolved
.../main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/RequestBatchBuffer.java
Show resolved
Hide resolved
...re/amazon/awssdk/services/sqs/internal/batchmanager/ChangeMessageVisibilityBatchManager.java
Outdated
Show resolved
Hide resolved
|
a04379b
into
feature/master/sqs-batch-manager
* Codegenerate BatchManager API under AsyncClient and Initail Interfaces for BatchManager (#5321) * Codegenerate BatchManager API under AsyncClient and Add empty initial Batchmanager interfaces and Implementations * Addressed review comments * Added Internal classes required for BatchManager Implementation * Revert "Added Internal classes required for BatchManager Implementation" This reverts commit 318969b. * Internal classes and RequestBatchManager Impelementation (#5418) * Added Internal classes required for BatchManager Implementation * Added Batch Send Implementation * Handled review comments * Handled review comments * Handled review comments * Made RequestBatchManager class a Abstract class * Checkstyle issues * Removed unused methods * New lines removed * Made public static to private state for sqsBatch functions * Constants added * Sonar cloud issues fixed * commit to check why test on codebuild * Increased Timeouts for get * Added abstract methods * Handled comments to remove Builders * Handled comments to take care when batchmanager closed while pending requests * Handled comments * Checkstyle issue * Added Consumer builders args for existing APIs of BatchManager (#5514) * Receive Batch Manager Implementation (#5488) * Add Recieve Buffer Queue And its related configuration * Update ReceiveBatch manager * Recieve Batch Manager Implementation * Receive Batch Manager Implemetation * Handled review comments * Checkstyle failure * Flsky test case fixed * Flaky test case fixed * Hamdled review comments * Handled comments * Removed ReceiveMessageCompletableFuture * SdkClosable implemented * Added ReceiveMessageBatchManager class for completeness * Checkstyle issues * Null checks * Handled comments from Zoe * Updated the defaults to 50ms same as V1 after surface area review * Revert "Updated the defaults to 50ms same as V1 after surface area review" This reverts commit e7d2295. * Bytes Based batching for SendMessageRequest Batching (#5540) * Initial changes * Initial changes 2 * Byte Based batching for SendMessage API * Byte Based batching for SendMessage API * Handled comments * Checkstyle issue * Add User Agent for Sqs Calls made using Automatic Batching Manager (#5546) * Add User Agent for Sqs Calls made using Automatic Batching Manager as hll/abm * Review comments * Update comments from PR 5488 (#5550) * Update comments of PR 5488 * Update comments from PR 5488 * Handled surface area review comments (#5563) * Initial version * Intermediate changes * Update after internal poll * ResponseCOnfiguration construction updated * RequestOverride configuration check added to Bypass batch manager * Handled review comments * Removed TODO since validations are handled in BatchPverrideConfiguration * Fix issue where the Scheduled Timeout was incorrectly completing the futures with empty messages (#5571) * Fix issue where the Scheduled Timeout was incorrectly completing the futures with empty messages * Handled review comments * Integ test for Automatic Request Batching (#5576) * feat(sqs): add BatchManager for client-side request batching to Amazon SQS The new BatchManager allows for simple request batching using client-side buffering, improving cost efficiency and reducing the number of requests sent to Amazon SQS. The client-side buffering supports up to 10 requests per batch and is supported by the SqsAsyncClient. Batched requests, along with receive message polling, help to increase throughput. * Add check for scheduledExecutor such that it not null when creating SqsAsyncBatchManager (#5582) * Add check for scheduledExecutor such that it not null when creating SqsAsyncBatchManager * Update services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/SqsAsyncBatchManagerBuilderTest.java Co-authored-by: David Ho <[email protected]> * Update services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/SqsAsyncBatchManagerBuilderTest.java Co-authored-by: David Ho <[email protected]> * Update services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/SqsAsyncBatchManagerBuilderTest.java Co-authored-by: David Ho <[email protected]> --------- Co-authored-by: David Ho <[email protected]> * Updating Timeouts in gets so that we dont wait infinitely --------- Co-authored-by: David Ho <[email protected]>
RequestManager Implementation details
Overview
The
RequestManager
is responsible for managing and executing batched requests in an efficient manner. It utilizes various batch managers to handle different types of requests such as sending messages, deleting messages, changing message visibility, and handling generic request batches. The design ensures that requests are processed in an optimized and scalable way by leveraging concurrent processing and batching techniques.Classes
1.
SendMessageBatchManager
2.
RequestBatchManager
3.
RequestBatchBuffer
4.
IdentifiableMessage
5.
DeleteMessageBatchManager
6.
DefaultSqsAsyncBatchManager
7.
ChangeMessageVisibilityBatchManager
8.
BatchingMap
9.
BatchingExecutionContext
10.
RequestBatchConfiguration
Key Design Considerations
Conclusion
The
RequestManager
design leverages batching and asynchronous processing to efficiently manage and execute SQS requests. The modular design with specific batch managers for different request types ensures flexibility and scalability, making it suitable for high-throughput applications.License