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

Add RequestContent to azure-core #21896

Closed
alzimmermsft opened this issue May 27, 2021 · 0 comments · Fixed by #21320
Closed

Add RequestContent to azure-core #21896

alzimmermsft opened this issue May 27, 2021 · 0 comments · Fixed by #21320
Assignees
Labels
Azure.Core azure-core Client This issue points to a problem in the data-plane of the library.
Milestone

Comments

@alzimmermsft
Copy link
Member

Create a new model class RequestContent which is capable of wrapping numerous request body types, such as ByteBuffer, InputStream, File/Path, etc, and providing a single interface for writing the contents over the wire. The purpose of this new type is the following:

Reducing API complexity

First, and foremost, RequestContent is expected to simplify the numerous potential solutions of sending a request body over the network. At this time, Flux<ByteBuffer> is the primary vessel for sending network request bodies, this type has limitations where disparate body types such as byte[], String, serializable objects, InputStream, etc need to be converted into a Flux<ByteBuffer>. This has resulted in both duplication of functionality for converting body contents into Flux<ByteBuffer> and difficulties in using Flux<ByteBuffer> APIs as not everyone is well versed in Reactor and asynchronous Java programming.

RequestContent's aim here is to simplify this into using a single interface which is able to abstract any conversions of request body types into what needs to be used to send network request bodies. This change is similar to what BinaryData has done for simplify API inputs and outputs into a single wrapping interface which can translate content into what user wants to consume it as or into how the user wants to provide it as input.

Less content copying

Next, RequestContent is expected to be used to reduce the copying of memory or loading disk contents into memory. Inherently, Flux<ByteBuffer> is almost always used as an in-memory representation, normally with ByteBuffer.wrap(byte[]). For certain request body types such as String, InputStream, File/Path, and serializable object the content is converted from that initial type into a byte[] and then wrapped by a ByteBuffer. This results in the content being store multiple times in different formats in memory, resulting in a much higher overhead than expected.

RequestContent's aim here is to maintain the base request body type for as long as possible until sending it over the network as the request body. And in some cases, such as File/Path and potentially InputStream, completely remove the need to load the content into memory, or loading the entire content into memory, and just write it directly to the network. Overall, this should reduce not only peak but general memory consumption when sending network requests.

@alzimmermsft alzimmermsft added Client This issue points to a problem in the data-plane of the library. Azure.Core azure-core labels May 27, 2021
@alzimmermsft alzimmermsft added this to the [2021] July milestone May 27, 2021
@alzimmermsft alzimmermsft self-assigned this May 27, 2021
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-java that referenced this issue Feb 16, 2023
[Hub Generated] Review request for Microsoft.ResourceHealth to add version preview/2022-10-01-preview (Azure#22479)

* Adds base for updating Microsoft.ResourceHealth from version preview/2022-05-01-preview to version 2022-10-01-preview

* Updates readme

* Updates API version in new specs and examples

* Dev resourcehealth/abhsinghal/2022 10 01 preview (Azure#21758)

* Added ImpactedResources for Tenant.

* Added new API listSecurityAdvisoryImpactedResources for Subscriptions and Tenants.

* Added Tenant ImpactedResources, SecurityImpactedResources.

* Changes to examples for Subscription ImpactedResources.

* Added resourceName pattern for ImpactedResourceNameParameter.

* Changes to example - SecurityAdvisoryImpactedResources_ListByTenantId_ListByEventId. Removed subscriptionId from unique resourceId.

* added fetchEventDetails initial commit (Azure#21896)

* added fetchEventDetails initial commit

* linter fixes

* removed filterparam

* re-add incorrectly deleted filter parameter

* removed query start time parameter

* Added EmergingIssues API paths from 2018-07-01. (Azure#21954)

* Added EmergingIssues API paths from 2018-07-01.

* Fix LintDiff error - x-ms-identifiers

* Fix LintDiff error - MissingTypeObject

* Changed resource definition from v1 to v3.

* Adding 2 new fields to AvailabilityStatuses response. (Azure#22081)

* Adding 2 new fields to AvailabilityStatuses response.

* Modified availabilitystatuses examples, changes to descriptions.

* Modified availabilitystatuses examples - 2

* Adds base for updating Microsoft.ResourceHealth from version preview/2022-05-01-preview to version 2022-10-01-preview

* Updates readme

* Updates API version in new specs and examples

* fix merge conflicts between main and dev-resourcehealth-Microsoft.ResourceHealth-2022-10-01-preview

* added the metadata api into swagger

* ran prettier

* fixed example file

* added pattern for issueName

* undo adding pattern and ran prettier

---------

Co-authored-by: abhishek-corp <104534488+abhishek-corp@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Core azure-core Client This issue points to a problem in the data-plane of the library.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant