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

[Internal] Binary Encoding: Adds performance tests with binary encoding enabled. #4943

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

aavasthy
Copy link
Contributor

Pull Request Template

Description

Update existing MockedItemBenchmark performance tests for methods CreateItemAsync, CreateItemStreamAsync, ReadItemAsync, ReadItemStreamAsync, UpsertItemAsync, UpsertItemStreamAsync, ReplaceItemAsync, ReplaceItemStreamAsync, DeleteItemAsync, DeleteItemStreamAsync which have binary encoding support. These tests will run in the pipeline and help determine in determining regression when binary encoding feature is enabled.
https://cosmos-db-sdk-public.visualstudio.com/cosmos-db-sdk-public/_build/results?buildId=52990&view=logs&j=aa2fd561-a338-5537-45ee-49ae22aea958&t=65500a81-e1c7-5931-1116-cabb8c832591
image

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Closing issues

To automatically close an issue: closes #IssueNumber

@aavasthy aavasthy self-assigned this Dec 30, 2024
@aavasthy aavasthy added the auto-merge Enables automation to merge PRs label Dec 30, 2024
@@ -137,6 +137,7 @@ jobs:
condition: and(succeeded(), eq(${{ parameters.IncludePerformance }}, true))
pool:
name: 'OneES'
timeoutInMinutes: 70
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the current run times of the tests? Is this just to conform to the rest of the benchmarks that have this timeout or do the tests actually take 70+ minutes to run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default timeout is 60 minutes and with my current setup the time was going to 63 minutes. As part of this PR, all existing MockedItmeBenchmark tests are running twice. Once with binary encoding enabled and once with binary encoding disabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

And will this run every PR or on the nightly/release pipelines only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Performance tests don't run with every PR. We manually run them here
https://cosmos-db-sdk-public.visualstudio.com/cosmos-db-sdk-public/_build?definitionId=78&_a=summary

includeDiagnosticsToString: false,
isClientMetricsEnabled: true) }
};
public static IItemBenchmark[] IterParameters = new IItemBenchmark[]
Copy link
Member

Choose a reason for hiding this comment

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

Can it be initialized always only in GlobalSetup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

"MockedItemBulkBenchmark.UpsertItem;[Type=OfTWithDistributedTracingEnabled]": "1208600.25",
"MockedItemBulkBenchmark.UpsertItem;[Type=Stream]": "768928.75"

"MockedItemBenchmark.CreateItem;[Type=OfT][EnableBinaryResponseOnPointOperations=True]": "38127.25",
Copy link
Member

Choose a reason for hiding this comment

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

Wow no impact at-all in any of the combinations? Can you please double check once again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so for checking regression, I added the exact same value we initially had these tests and set it for both flag enabled and disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I can try adding assertion within the test class to ensure binary encoding with flag enabled code path is working through.

Copy link
Member

Choose a reason for hiding this comment

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

Yah the gates also might need to be refresh to include binary runs.

if (request.ResourceAddress.EndsWith(MockedItemBenchmarkHelper.ExistingItemId))
{
return new DocumentServiceResponse(
response = request.ResourceAddress.EndsWith(MockedItemBenchmarkHelper.ExistingItemId)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Conditional part can be scoped to just the MemoryStream part.

Copy link
Member

Choose a reason for hiding this comment

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

Can this be done outside of the above If so-that all operations can use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

new MemoryStream(MockRequestHelper.testItemFeedResponsePayload),
headers,
System.Net.HttpStatusCode.OK
);
}
else
Copy link
Member

Choose a reason for hiding this comment

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

If response declaration initialized to null then this else block is not needed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the else block


return null;
// Check if binary encoding is enabled and this is a supported point operation
if (ConfigurationManager.IsBinaryEncodingEnabled() && MockRequestHelper.IsPointOperationSupportedForBinaryEncoding(request))
Copy link
Member

Choose a reason for hiding this comment

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

Can it be based on the incoming request it-self?

Copy link
Member

Choose a reason for hiding this comment

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

I.e. avoid ConfigurationManager part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the check for ConfigurationManager.IsBinaryEncodingEnabled() and instead checking the request header instead
(request.Headers.Get(HttpConstants.HttpHeaders.SupportedSerializationFormats)


// Converts the response payload into binary if needed
// This simulates binary serialization using the same approach as in MockedItemBenchmarkHelper.
private static DocumentServiceResponse ConvertToBinaryIfNeeded(DocumentServiceResponse response)
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on doing the conversation once, cache and clone?
Will keep the side-affects/variability from test code as minimal as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the code and using a dictionary instead to avoid repeated re-serialization

private static byte[] GetOrAddBinaryPayload(byte[] textPayload)
{
// A simple key is the base64 of the payload. For large payloads, consider hashing.
string key = Convert.ToBase64String(textPayload);
Copy link
Member

Choose a reason for hiding this comment

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

One other option is to have choose binary vs non-binary byte[] at the source it-self. This will avoid the Dict nad Base64 key encoding cost as well.

Copy link
Member

Choose a reason for hiding this comment

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

BatchResponse is interesting it's the only dynamic data part, that might need to pay the binary conversation cost.
So for batch benchmarks by-definition see the regression (might not be

@aavasthy aavasthy removed the auto-merge Enables automation to merge PRs label Jan 16, 2025
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.

3 participants