Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reduce memory allocationt.#2109

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
xljiulang wants to merge54 commits intodotnet:master
base:master
Choose a base branch
Loading
fromxljiulang:buffer-reader

Conversation

@xljiulang
Copy link
Contributor

Now, memory allocation is reduced to 50%.
Job=.NET 8.0 Runtime=.NET 8.0

MethodPayloadSizeMeanErrorStdDevRatioRatioSDGen0Gen1AllocatedAlloc Ratio
Send_1000_Messages_New81928.727 ms0.1393 ms0.1368 ms1.000.001875.000062.50008.55 MB1.00
Send_1000_Messages_Old819218.182 ms0.1461 ms0.1220 ms2.080.033593.7500250.000016.89 MB1.98
Send_1000_Messages_New6553640.791 ms0.8041 ms1.8475 ms1.000.0011076.92313307.692363.22 MB1.00
Send_1000_Messages_Old6553632.204 ms0.6323 ms0.7997 ms0.790.0421200.00007066.6667127.05 MB2.01

@xljiulangxljiulang changed the titleReduce memory allocation of DecodePublishPacket.Reduce memory allocationt.Nov 19, 2024
@xljiulang
Copy link
ContributorAuthor

xljiulang commentedNov 19, 2024
edited
Loading

After refactoring MqttBufferReader, the MQTTnet project can still be reduced to 50% of the pre-pr level, and MQTTnet.AspNetCore can be reduced to 0.58% of the pre-pr level.

MethodPayloadSizeMeanErrorStdDevMedianRatioRatioSDGen0AllocatedAlloc Ratio
AspNetCore_Send_1000_Messages102429.49 ms0.568 ms0.697 ms29.41 ms1.000.00156.2500738.92 KB1.00
MQTTnet_Send_1000_Messages102453.17 ms1.041 ms1.022 ms53.35 ms1.800.05500.00002325.25 KB3.15
AspNetCore_Send_1000_Messages819232.57 ms0.634 ms0.802 ms32.48 ms1.000.00125.0000735.07 KB1.00
MQTTnet_Send_1000_Messages819254.95 ms0.537 ms0.476 ms55.06 ms1.690.052555.55569326.39 KB12.69
AspNetCore_Send_1000_Messages6553658.99 ms1.145 ms1.406 ms58.81 ms1.000.00125.0000758.25 KB1.00
MQTTnet_Send_1000_Messages6553684.97 ms4.546 ms13.405 ms78.82 ms1.310.1016714.285766269.48 KB87.40

{
publicstaticTask<byte[]>ExecuteAsync(thisIMqttRpcClientclient,TimeSpantimeout,stringmethodName,stringpayload,MqttQualityOfServiceLevelqualityOfServiceLevel,IDictionary<string,object>parameters=null)
[Obsolete("Use the method ExecuteTimeOutAsync instead.")]
publicstaticasyncTask<byte[]>ExecuteAsync(thisIMqttRpcClientclient,TimeSpantimeout,stringmethodName,stringpayload,MqttQualityOfServiceLevelqualityOfServiceLevel,IDictionary<string,object>parameters=null)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Do we need to keep this method to be compatible with the old version of the API prototype?
After removing these two [Obsolete] methods, we can also overload the ExecuteTimeOutAsync method to the ExecuteAsync method name, and put the TimeSpan timeout parameter in the last parameter, corresponding to the cancellationToken parameter position.

<NuGetAudit>true</NuGetAudit>
<NuGetAuditLevel>low</NuGetAuditLevel>
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<!--<AnalysisLevel>latest-Recommended</AnalysisLevel>-->
Copy link
Contributor

@mregenmregenDec 4, 2024
edited
Loading

Choose a reason for hiding this comment

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

try this on .NET 9, if you commented it out because of the 100s of warning messages

<PropertyGroup>  <AnalysisLevel>latest</AnalysisLevel>  <AnalysisMode>recommended</AnalysisMode>  <AnalysisModeStyle>default</AnalysisModeStyle></PropertyGroup>

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

That's 100s of error messages! We can unify this issue in#2120.

Copy link
Contributor

Choose a reason for hiding this comment

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

@xljiulang
Copy link
ContributorAuthor

Results of MessageProcessingBenchmark before and after PR.

BenchmarkDotNet v0.13.12, Windows 11 (10.0.26100.2314)12th Gen Intel Core i5-12450H, 1 CPU, 12 logical and 8 physical cores.NET SDK 9.0.101  [Host]   : .NET 8.0.10 (8.0.1024.46610), X64 RyuJIT AVX2  .NET 8.0 : .NET 8.0.10 (8.0.1024.46610), X64 RyuJIT AVX2Job=.NET 8.0  Runtime=.NET 8.0
MethodPayloadSizeMeanErrorStdDevRankGen0Gen1Allocated
Send_1000_Messages_BeforePR102428.66 ms0.563 ms1.151 ms1781.2500-4.48 MB
Send_1000_Messages_BeforePR409631.88 ms0.237 ms0.198 ms23187.5000187.500013.27 MB
Send_1000_Messages_BeforePR819233.92 ms0.208 ms0.185 ms37000.0000866.666725.05 MB
MethodPayloadSizeMeanErrorStdDevRankGen0Allocated
Send_1000_Messages_AfterPR102429.55 ms0.229 ms0.215 ms1281.25001.75 MB
Send_1000_Messages_AfterPR409631.02 ms0.207 ms0.173 ms2281.25001.76 MB
Send_1000_Messages_AfterPR819232.86 ms0.172 ms0.144 ms3250.00001.84 MB

@xljiulang
Copy link
ContributorAuthor

The development work of this PR has been completed, but it depends on#2115, otherwise some unit tests will fail.

.Build();

awaitmqttClient.PublishAsync(applicationMessage,CancellationToken.None);
awaitmqttClient.PublishStringAsync(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are the samples changed? They show how to use the message builder. Please add new samples which are targeting performance relevant ways of publising.

<NuGetAudit>true</NuGetAudit>
<NuGetAuditLevel>low</NuGetAuditLevel>
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<!--<AnalysisLevel>latest-Recommended</AnalysisLevel>-->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this commented out?


Task<byte[]>ExecuteAsync(stringmethodName,byte[]payload,MqttQualityOfServiceLevelqualityOfServiceLevel,IDictionary<string,object>parameters=null,CancellationTokencancellationToken=default);
{
Task<ReadOnlySequence<byte>>ExecuteAsync(stringmethodName,ReadOnlySequence<byte>payload,MqttQualityOfServiceLevelqualityOfServiceLevel,IDictionary<string,object>parameters=null,CancellationTokencancellationToken=default);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a breaking change to me. Is there a way to support all three methods for now?

@chkr1011
Copy link
Collaborator

@xljiulang I want to merge this PR but it contains too many changes and too many breaking API changes. Is there a way to split this into smaller pieces and avoiding breaking changes (for now, using obsolete attribute etc)?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chkr1011chkr1011chkr1011 left review comments

+1 more reviewer

@mregenmregenmregen left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@xljiulang@chkr1011@mregen

[8]ページ先頭

©2009-2025 Movatter.jp