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 round trip time measurement to candidate pair #731

Merged
merged 2 commits into from
Sep 16, 2024
Merged

Conversation

boks1971
Copy link
Contributor

Use the round trip time measurement to populate RTT fields in CandidatePairStats.

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.20%. Comparing base (277014e) to head (47deda5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #731      +/-   ##
==========================================
+ Coverage   79.11%   79.20%   +0.08%     
==========================================
  Files          41       41              
  Lines        3783     3799      +16     
==========================================
+ Hits         2993     3009      +16     
  Misses        558      558              
  Partials      232      232              
Flag Coverage Δ
go 79.20% <100.00%> (+0.08%) ⬆️
wasm 22.36% <0.00%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@cnderrauber cnderrauber left a comment

Choose a reason for hiding this comment

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

looks good!

@Sean-Der
Copy link
Member

Thank you @boks1971 looks great! Mind adding some simple coverage to this.

Just assert values are non-zero, so someone doesn't regress it.

candidatepair.go Outdated
@@ -28,6 +30,12 @@ type CandidatePair struct {
state CandidatePairState
nominated bool
nominateOnBindingSuccess bool

// stats
statsMu sync.RWMutex
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about making these atomic (if possible?)

Having another lock on such a critical path (inbound network traffic) might eventually be targeted for optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The STUN pings are usually once every few seconds. So, I think it should be fine.

But, I will look at atomics.

Copy link
Member

@Sean-Der Sean-Der left a comment

Choose a reason for hiding this comment

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

possible to make atomics, add tests

@boks1971
Copy link
Contributor Author

possible to make atomics, add tests

@Sean-Der Can you please have a look now? Made changes in this commit.

I am still not able to squash commit the changes. Lint fails. Will fix that.

@boks1971
Copy link
Contributor Author

possible to make atomics, add tests

@Sean-Der Can you please have a look now? Made changes in this commit.

I am still not able to squash commit the changes. Lint fails. Will fix that.

There is a race with updating totalRoundTripTime because it is a read-modify-write. What is the best way to handle that with atomics?

Use the round trip time measurement to populate RTT fields in
CandidatePairStats.

Atomic and tests
candidatepair.go Outdated
if prevTotalRoundTripTime != nil {
totalRoundTripTime += *prevTotalRoundTripTime
}
p.totalRoundTripTime.CompareAndSwap(prevTotalRoundTripTime, &totalRoundTripTime)
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 just be Store?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following sequence will get the wrong value

  1. goroutine A reads value A
  2. Another update happens and goroutine B reads value A
  3. goroutine A adds to the total (value A + rtt A)
  4. goroutine B adds to the total (value A + rtt B) <-- this is the problematic
  5. Depending on who write first, the final value could be value A + rtt A or value A + rtt B. Both are wrong. The correct value is value A + rtt A + rtt B.

There is no strong reason to use CompareAndSwap. Store would store both values whatever order it happens in. CompareAndSwap will store only the first value.

I think I am doing to change to this to just int64 and do Duration.Nanoseconds() so that I can use atomic.AddInt64().

Will make that change now.

@Sean-Der
Copy link
Member

Is the race possible (since we only process one packet at a time?)

The issue I was avoiding was users being able to block recv by calling APIs.

@boks1971
Copy link
Contributor Author

Is the race possible (since we only process one packet at a time?)

The issue I was avoiding was users being able to block recv by calling APIs.

That's true. But, to make things simpler, I just changed it to int64 nanoseconds in this commit. Will go ahead and use that. Can change it later if needed.

@boks1971 boks1971 merged commit 2d9be9b into master Sep 16, 2024
15 checks passed
@boks1971 boks1971 deleted the raja_rtt branch September 16, 2024 18:29
boks1971 added a commit that referenced this pull request Sep 16, 2024
* Add round trip time measurement to candidate pair

Use the round trip time measurement to populate RTT fields in
CandidatePairStats.

Atomic and tests

* Use int64 nanosecnods to make atomic easier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants