-
Notifications
You must be signed in to change notification settings - Fork 605
simplify missed heartbeat recognition #854
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
simplify missed heartbeat recognition #854
Conversation
Yes, we don't need perfect precision here simply for the fact that the absolute recommended minimum for heartbeat timeout is 5 seconds, and in most cases something closer to 15-60 seconds would be reasonable. |
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.
If we use a monotonically growing counter that is incremented every time we read a frame, on a long running connection we should overflow int
in less than 3 days at a rate of 10K messages/second.
How much of an improvement does this yield? The "ticking overflowing counter" approach is worrisome to me.
Actually we would overflow
An unsigned 64-bit integer would last us quite a bit longer (over 1900 years or so if my math is correct). |
1a4c3ac
to
2e8ff5d
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.
The NotifyHeartbeatListener() was showing up on my analysis
Can we get more details about what "showing up on my analysis" means?
@michaelklishin I tested this commit using the following code. As @bollhals states we don't care what the value of
|
OK, this looks like a simplification overall then. Let's wait for some profiler numbers to assess the difference. |
Thanks for the comments, I thought about the overflow but somehow I thought that it will never happen. Glad you did the math. I've checked again the implementation and I think we can even make it simpler. Since we don't care about the value, just that it changed, it should also be implementable with just 1 normal bool variable. |
/reminder to squash before merge |
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.
@bollhals I am probably mis-reading the screenshots in this comment, but it seems like the number of method calls to NotifyHeartbeatListener
should be equal to the number of calls to ReadFrame
. You can see that in your first screenshot, but the second one shows far fewer calls to NotifyHeartbeatListener
which seems to suggest that the code run in the second example isn't what is shown in this PR. Please correct me if I am mistaken!
I wasn't sure either, and I had to do something else first. |
@bollhals awesome, I really appreciate the explanation. |
simplify missed heartbeat recognition (cherry picked from commit ef01562)
Backported to |
Proposed Changes
The
NotifyHeartbeatListener()
was showing up on my analysis. Even though it is fairly small and quick, but it is called for every received frame.I think this simplified implementation should be fast and as safe as before.
Some comments to the implementation:
Types of Changes
Checklist
CONTRIBUTING.md
document