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

Extend server client ResetStatistics() to reset all client statistics not only channel... #1587

Merged
merged 1 commit into from Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/MQTTnet/Server/Internal/MqttClient.cs
Expand Up @@ -83,6 +83,7 @@ public sealed class MqttClient
public void ResetStatistics()
{
ChannelAdapter.ResetStatistics();
Statistics.ResetStatistics();
}

public async Task RunAsync()
Expand Down
8 changes: 7 additions & 1 deletion Source/MQTTnet/Server/Internal/MqttClientStatistics.cs
Expand Up @@ -73,7 +73,13 @@ public void HandleReceivedPacket(MqttPacket packet)
LastNonKeepAlivePacketReceivedTimestamp = LastPacketReceivedTimestamp;
}
}

public void ResetStatistics(){
Copy link
Member

Choose a reason for hiding this comment

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

Personally I'd structure it like done in #1590 with an extra struct to hold the values.
And use Volatile.Read/Write instead of Interlocked.Exchange -- see PR for reason.

Copy link
Contributor Author

@damikun damikun Nov 26, 2022

Choose a reason for hiding this comment

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

Will have a look and update... Inpull i just fit what was used in lib sources...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I will merge the pull request because it fixes the bug in the first place. We can then discuss how it is done and how to optimize it in your pull request.

Interlocked.Exchange(ref _sentApplicationMessagesCount,0);
Interlocked.Exchange(ref _receivedApplicationMessagesCount,0);
Interlocked.Exchange(ref _sentPacketsCount,0);
Interlocked.Exchange(ref _receivedPacketsCount,0);
Comment on lines +79 to +80
Copy link
Member

Choose a reason for hiding this comment

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

Should these be set to 1?
I'm asking because of

// Start with 1 because the CONNACK packet is not counted here.
long _receivedPacketsCount = 1;
// Start with 1 because the CONNECT packet is not counted here.
long _sentPacketsCount = 1;

BTW: there should be a space after the ,.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion 0 is fine because the user wants so to reset the entire statistics. The initial 1 is required to have correct values directly after start.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah as @chkr1011 said this is user reset.. 1 is only on init when client open connection...

}

public void HandleSentPacket(MqttPacket packet)
{
if (packet == null)
Expand Down